使用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已经执行或已执行完毕。谢谢

解决方案 »

  1.   

    x<300已经执行,x=0执行完毕
      

  2.   

    我是想在WebBrowser中判断js已经执行或已执行完毕。
    $("#direct").html("Please Click "+key); 
    这句是在30秒后显示Please Click,可是在webBrowser.DocumentText却找不到。
      

  3.   

    mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)WebBrowser1.Document;
    mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)doc.parentWindow;
    object o = win.GetType().InvokeMember("x", BindingFlags.GetProperty, null, win, new Object [] {});
      

  4.   

    谢谢,但是不怎么明白,上网找一下mshtml用法,也没有讲的太清楚的。能不能具体一些,谢谢。
      

  5.   

    javascript是建立在COM之上的,设置变量/调用函数是通过IDispatch来实现的
    在.NET里调用IDispatch里的方法是可以通过反射来实现
      

  6.   

    mshtml方面你可以参考这篇文章:http://www.tongyi.net/develop/cshap/1057438.html
      

  7.   

    C# codemshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)WebBrowser1.Document; 
    mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)doc.parentWindow; 
    object o = win.GetType().InvokeMember("x", BindingFlags.GetProperty, null, win, new Object [] {}); 
    这样写怎么才判断timer.js运行了
      

  8.   

    Convert.toInt32(o)<300已经执行
    Convert.toInt32(o)=0执行完毕
      

  9.   

    mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)web.Document;
    //无法转换,我用的是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并不运行
    }