使用WebBrowser编程,在打开的网站中有一个timer.js
代码如下:
statusWidth=1;
x=300;function next(num) {
if(x == 0) {parent.location.href='clickfinal.php?button_clicked='+num+'&ad='+adid+'&pretime='+pretime+'';}
else { alert("You must wait for the counter to reach 0"); }
}
function timer() {
x--;
if(x == 0) {
$("#timer").hide();
$("#buttonBlock").show();
$("#direct").html("Please Click "+key);
}
else {
statusWidth+=1;
$("#timerStatus").width(statusWidth);
setTimeout('timer()', 100);
}
}$(document).ready(function(){
timer();
});
我怎么才能判断这个timer.js已经执行或已执行完毕。谢谢
代码如下:
statusWidth=1;
x=300;function next(num) {
if(x == 0) {parent.location.href='clickfinal.php?button_clicked='+num+'&ad='+adid+'&pretime='+pretime+'';}
else { alert("You must wait for the counter to reach 0"); }
}
function timer() {
x--;
if(x == 0) {
$("#timer").hide();
$("#buttonBlock").show();
$("#direct").html("Please Click "+key);
}
else {
statusWidth+=1;
$("#timerStatus").width(statusWidth);
setTimeout('timer()', 100);
}
}$(document).ready(function(){
timer();
});
我怎么才能判断这个timer.js已经执行或已执行完毕。谢谢
$("#direct").html("Please Click "+key);
这句是在30秒后显示Please Click,可是在webBrowser.DocumentText却找不到。
mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)doc.parentWindow;
object o = win.GetType().InvokeMember("x", BindingFlags.GetProperty, null, win, new Object [] {});
在.NET里调用IDispatch里的方法是可以通过反射来实现
mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)doc.parentWindow;
object o = win.GetType().InvokeMember("x", BindingFlags.GetProperty, null, win, new Object [] {});
这样写怎么才判断timer.js运行了
Convert.toInt32(o)=0执行完毕
//无法转换,我用的是vs2005
void web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)web.Document.DomDocument;
//这样可以运行
mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)doc.parentWindow;
object o = win.GetType().InvokeMember("x", System.Reflection.BindingFlags.GetProperty, null, win, new Object[] { });
MessageBox.Show(Convert.ToInt32(0).ToString());
//可是MessageBox并不运行
}