[C#] 纯文本查看 复制代码
public Form2()
{
InitializeComponent();
string url = string.Format("file:///{0}/WebFiles/into.html", Application.StartupPath.Replace("\\","/"));
this.webBrowser1.Url = new System.Uri(url, System.UriKind.Absolute);
webBrowser1.ObjectForScripting = this;
}
int ints = 0;
ProgressBar ProgressBar1;
private void button1_Click(object sender, EventArgs e)
{
//object[] objects = new object[1];
// objects[0] = "c# call javascript "+ints.ToString();
// webBrowser1.Document.InvokeScript("Messageaa", objects);
ints++;
}
public string getint ()
{
return ints.ToString();
}
bool needreload = true;
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string html = webBrowser1.DocumentText;
if (needreload)
{
//webBrowser1.DocumentText = @"";
needreload = false;
}
}
web代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<script src="./echarts.min.js" type="text/javascript"></script>
<script type="text/javascript">
function Messageaa(message){
alert(message);
}
function setdiv(){
var str="c# int value="+window.external.getint();
document.getElementById('test1').innerText=str;
setTimeout(function(){
setdiv();
},3000);
}
</script>
</head>
<body>
test interactive web page in winfrom
<input type='button' value='get' onclick='setdiv()' />
<div id="test1"></div>
</body>
</html>