c# winform 如何要实现引入外部js文件?
比如c# winform中如何要引入外部js文件(类似html中的通过script标签引入外部js文件的效果)
<script type='text/javascrit' src='http://www.xxx.com/a.js'></script>
a.js中的内容如下:
var Num=3;
fucntion getNum(){
return x;
}
Microsoft.Jscript.dll中可以动记解释javascrit代码,但当js内容比较多时,如何实现类似html页面中通过<script>标签引入外部js文件的功能?
[解决办法]
webBrowser1.DocumentText =
@"<html><head>
<script type='text/javascript'>
function testFunction() {
alert('test');
}
</script>
</head><body></body></html>";
webBrowser1.Document.InvokeScript("testFunction");
Dim ele As HtmlElement = MyWebbrowser1.Document.CreateElement("script")
ele.SetAttribute("type", "text/javascript")
ele.SetAttribute("text", "(function(){try{alert('文本')}catch(ex){alert(ex)}})()")
MyWebbrowser1.Document.Body.AppendChild(ele)HtmlElement ele = MyWebbrowser1.Document.CreateElement("script");
ele.SetAttribute("type", "text/javascript");
ele.SetAttribute("text", "(function(){try{alert('文本')}catch(ex){alert(ex)}})()");
MyWebbrowser1.Document.Body.AppendChild(ele);