webbrowser加载外部html文件和外部js文件,代码示例:
webBrowser1.Navigate(
@"
c:\test.htm
"
);
外部html文件代码:
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<!
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文件代码:
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
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);
}