调用HTML内部的JavaScript的函数使用webBrowser1.Document.InvokeScript("myFunction")可以调用成功,但JavaScript通过外部引用的,如:<script type="text/javascript" src="../../../scripts/ReservationRequest.js"></script>,再用InvokeScript就调用失败,这是为什么呢?本人刚接触,不太了解原理
调试欢乐多
webbrowser加载外部html文件和外部js文件,代码示例:webBrowser1.Navigate(@"c:\test.htm");
外部html文件代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script type="text/javascript" src="JScript1.js"></script>
</head>
<body onload="addHello()">
</body>
</html>
外部js文件代码:
function addHello(){
var bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.border="1px solid #333";
bgObj.innerHTML="this is text from js file!";
document.body.appendChild(bgObj);
}