用Webbrowser 組件打開一個網頁后。如何通過一個按鈕執行一個外部JS,條件是不能將這個JS文件寫入當前網頁。類似於MYIE的JS插件功能一樣!!
先在此謝過!

解决方案 »

  1.   


    (tembeddedwb(pg1.ActivePage.Components[0]).Document as IHTMLDocument2 ).parentWindow.execScript('document.body.style.zoom="250%"', 'javascript');在試的過程中發現這一句報錯。而(tembeddedwb(pg1.ActivePage.Components[0]).的其它動作是沒問題的當然在非動態創建時是不會出錯的:tembeddedwb1.Document as IHTMLDocument2 ).parentWindow.execScript('document.body.style.zoom="250%"', 'javascript');
      

  2.   

    期待高手出現。自己先頂上去,上面的語句沒有問題。是我自己把script禁止了
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    vDocument: IHTMLDocument2;
    begin
    vDocument := WebBrowser1.Document as IHTMLDocument2;
    if not Assigned(vDocument) then Exit;
    vDocument.parentWindow.execScript(
    'function $(id)'#13#10 +
    '{'#13#10 +
    ' return document.getElementById(id);'#13#10 +
    '}'#13#10 +
    ''#13#10 +
    '$("Email").value = "' + Edit1.Text + '";'#13#10 +
    '$("passwd").value = "' + Edit2.Text + '";'#13#10 +
    '$("PersistentCookie").checked = true;'#13#10 +
    '$("signIn").click();'#13#10,
    'javascript');
    end;你看看对你有用没有啊
      

  4.   

    可是我将
    'function $(id)'#13#10 + 
    '{'#13#10 + 
    ' return document.getElementById(id);'#13#10 + 
    '}'#13#10 + 
    ''#13#10 + 
    '$("Email").value = "' + Edit1.Text + '";'#13#10 + 
    '$("passwd").value = "' + Edit2.Text + '";'#13#10 + 
    '$("PersistentCookie").checked = true;'#13#10 + 
    '$("signIn").click();'#13#10, 
    'javascript'); 
    这一段用一变量代替,却又不能执行parentWindow.execScript(变量, 'javascript');
      

  5.   

    你可以把js文件包含进这个网页,然后就可以写个script直接调用哦。