InternetExplorerClass internetExplorer1; private void internetExplorer1_DocumentComplete(object pDisp, ref object URL)
{
MessageBox.Show("triggered");
IHTMLDocument2 doc;
IHTMLWindow2 win;
doc=(IHTMLDocument2)internetExplorer1.Document;
win=doc.ParentWin;
win.ExecuteScript("alert(\"hello\");","javascript");
}发现触发 DocumentComplete 的时候会显示 "triggered" ,但不会显示 "hello"
请问是哪里出了问题?应怎样改正?
用上面的方法,用 axWebBrowser(内置浏览器)是能正确显示 "hello" 的,为什么用 InternetExplorerClass(外置浏览器)就会出错?
{
MessageBox.Show("triggered");
IHTMLDocument2 doc;
IHTMLWindow2 win;
doc=(IHTMLDocument2)internetExplorer1.Document;
win=doc.ParentWin;
win.ExecuteScript("alert(\"hello\");","javascript");
}发现触发 DocumentComplete 的时候会显示 "triggered" ,但不会显示 "hello"
请问是哪里出了问题?应怎样改正?
用上面的方法,用 axWebBrowser(内置浏览器)是能正确显示 "hello" 的,为什么用 InternetExplorerClass(外置浏览器)就会出错?
2、设置断点还怕找不到错误的地方?
据我了解,对于一个外置的浏览器,要在它 documentcomplete 的时候找出其相关的 IHTMLWindow2 接口 是不可能的(不知是我孤陋寡闻还是确实不行了,请小心求证)
不过,当浏览器 documentcomplete 后,对主对话框进行操作,必须触发的一个事件就是 focus
所以可以在对 focus 事件的处理函数里添加:
doc=(IHTMLDocument2)internetExplorer1.Document;
win=doc.ParentWin;
不是 focus 事件,而是 activate 事件
而且 doc=(IHTMLDocument2)internetExplorer1.Document; 是可以在 documentcomplete 处理函数里添加的
相关代码如下:
private void Form1_Activated(object sender, System.EventArgs e)
{
winout2=(IHTMLWindow2)docout2.parentWindow;
}
请问楼主 这个命令是做什么的? \" 改成 ‘ 可以吗?
doc=(IHTMLDocument2)internetExplorer1.Document;
win=doc.ParentWin;
win.ExecuteScript("alert(\"hello\");","javascript");
三行的意思是:在 internetExplorer1 的页面执行 alert("hello"); 这句Javascript
把 \" 改成 ' 也是可以的
你的方法我试过,在 IHTMLWindow2 指向方面是成功的,但无法做到一加载完成马上执行javascript。
请问有能 DocumentComplete 后马上执行 script 的方法吗?