delphi 웹브라우저

6071 단어 WebBrowser
var   Form   :     IHTMLFormElement     ;
        D:IHTMLDocument2     ;
begin
    with   WebBrowser1   do   begin
          D   :=   Document   as   IHTMLDocument2;
          Form   :=   D.Forms.item( 'form1 ',0)   as   IHTMLFormElement;   //form1    
          //title        
        (form.item( 'title ',0)   as   IHTMLElement).setAttribute( 'value ',s_title,0);  
        (form.item( 'content ',0)   as   IHTMLElement).setAttribute( 'value ',edit1.text,0);
        (form.item( 'add ',0)   as   IHTMLElement).click;//add button  
    end;

delphi의 WebBrowser에서 Input 양식 값 가져오기 및 설정하기
var
    i:Integer;
    myole:oleVariant;
begin
    myole := wb1.Document;
    for i := 0 to myole.all.length - 1 do
    begin
        if myole.all.item(i).tagName = 'INPUT' then
        begin

            mmo1.Lines.Add(myole.all.item(i).name);

            mmo1.Lines.Add(myole.all.item(i).value);
        end;
    end;

end;
WebBrowser1.GoHome; //        
WebBrowser1.Refresh; //  
WebBrowser1.GoBack; //  
WebBrowser1.GoForward; //  
WebBrowser1.Navigate('...'); //      
WebBrowser1.Navigate('about:blank'); //     
--------------------------------------------------------------------------------
//     ,    ...

WebBrowser1.Navigate('about:<head><title>  ></title><body>    </body>');
--------------------------------------------------------------------------------
//          :

procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
i: Integer;
begin
s := WebBrowser1.OleObject.document.Script.str;
i := WebBrowser1.OleObject.document.Script.num;
ShowMessage(s); //Hello
ShowMessage(IntToStr(i)); //99

//      :
s := WebBrowser1.OleObject.document.parentWindow.str;
i := WebBrowser1.OleObject.document.parentWindow.num;
ShowMessage(s); //Hello
ShowMessage(IntToStr(i)); //99
end;
          :
<script>
var
str = "Hello";
i = 99;
</script>

--------------------------------------------------------------------------------

//          :

procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.OleObject.document.parentWindow.MB(); //HTML-Js

//        ,   :
WebBrowser1.OleObject.document.parentWindow.execScript('MB()','JavaScript'); //HTML-Js
end;
       :
<script>
function MB(){
alert('HTML-Js');
}
</script>

--------------------------------------------------------------------------------

//                   

procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if WebBrowser1.Application = pDisp then
begin
Text := '      !';
end;
end;

--------------------------------------------------------------------------------

//          :
WebBrowser1.OleObject.document.body.bgcolor := '#FF0000';
WebBrowser1.OleObject.document.body.background := '...    ';
--------------------------------------------------------------------------------
//    ID      :
var
s: string;
begin
s := WebBrowser1.OleObject.document.getElementByID('span1').innerText;
ShowMessage(s); //   span1       

//  :
s := WebBrowser1.OleObject.document.parentWindow.span1.innerText;
ShowMessage(s); //   span1       

//   :
WebBrowser1.OleObject.document.parentWindow.span1.style.display := 'none';
end;
          :
<span id=span1>   span1       </span>


--------------------------------------------------------------------------------

//      
var
s: string;
begin
s := WebBrowser1.OleObject.document.body.innerHTML; //body      
s := WebBrowser1.OleObject.document.body.outerHTML; //body      ,   body  
s := WebBrowser1.OleObject.document.documentElement.innerHTML; //html      
end;
--------------------------------------------------------------------------------
//WebBrowser       

//    ApplicationEvents1,   Message  

//      
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
with Msg do
begin
if not IsChild(WebBrowser1.Handle, hWnd) then Exit;
Handled := (message = WM_RBUTTONDOWN) or (message = WM_RBUTTONUP) or (message = WM_CONTEXTMENU);
end;
end;

//      
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var mPoint: TPoint;
begin
if IsChild(WebBrowser1.Handle, Msg.Hwnd) and
((Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP)) then
begin
GetCursorPos(mPoint); //      
PopupMenu1.Popup(mPoint.X, mPoint.Y); //  popupmenu1   
Handled:=True;
end;
end;
--------------------------------------------------------------------------------
//     
begin
WebBrowser1.Navigate('about:blank');
WebBrowser1.OleObject.Document.Writeln('ok');
end; 

자동 로그인
  frames   
var
o : Olevariant;
begin
o := WebBrowser.OleObject.document.all.item('LoginUserID',0);    //    username    
o.value := 'TEST';
o := WebBrowser.oleobject.document.all.item('LoginPassword',0); //    password    
o.value := 'TEST'
WebBrowser.oleobject.document.Forms.Item(0, 0).submit;           //       
{
o :=WebBrowser.oleobject.document.all.item('Login',0);           //           
o.Click;   //    ,           
}
end;
  frames   ,FrameIndex Frame   
var
o : Olevariant;
begin
//    username    
o := WebBrowser.oleobject.document.documentelement.document.frames.item(FrameIndex).document.all.item('LoginUserID',0);
o.value := 'TEST';
//    password    
o := WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.all.item('LoginPassword',0);
o.value := 'TEST'
//       
WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.Forms.Item(0, 0).submit;
{
//           
o :=WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex)..document.all.item('Login',0);
o.Click;    //    ,           
}
end; 

좋은 웹페이지 즐겨찾기