0
我正在使用VB.NET 2008.我正在构建一个名为“browser1”的浏览器的应用程序。当我浏览像“http://www.google.com”(不是“file:/// c:/test.html”)的URL时,它成功加载了页面。我正在使用代码在此页面中注入一个JavaScript文件。如何在非本地网页中注入JavaScript文件并调用它
Dim mScript As HtmlElement
Dim mHead As HtmlElement
Dim jsPath As String
jsPath = (SoftwareROOT.Replace("\", "/")) & "/plugin.js"
With Browser1
mHead = Browser1.Document.GetElementsByTagName("head")(0)
mScript = .Document.CreateElement("script")
mScript.SetAttribute("type", "text/javascript")
mScript.SetAttribute("src", jsPath)
mHead.AppendChild(mScript)
.Document.InvokeScript("plugin_main")
End With
该代码成功创建新元素。但是当它试图调用脚本(最后第二行)时,它无法运行脚本。
注:
- 文件路径即可。
- 代码成功地与本地页面(如“c:\ test.html”)一起工作。
- “plugin_main”是javascript alert()的简单函数。
什么是错误信息? – Peter 2011-12-20 20:51:23
没有错误。 – Shahrukh 2011-12-20 21:14:55