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>
<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);
}
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);
}
本文介绍如何使用WebBrowser控件加载本地HTML文件及外部JS文件,并展示了一个具体的示例,包括HTML文件如何引用外部JS文件并在页面加载时执行JS函数。

2871

被折叠的 条评论
为什么被折叠?



