Winform中调用js函数

            var wb = new WebBrowser();
            wb.AllowNavigation = true;
            wb.ScriptErrorsSuppressed = false;
            wb.Navigate("about:blank");
            WaitWebbrowser(wb);
            wb.Document.Write("<script>function urlEncode(url){ return encodeURIComponent(encodeURI(url)); }</script>");
            MessageBox.Show(wb.Document.InvokeScript("urlEncode", new object[] { @"http://wwww.baidu.com/音乐" }).ToString());
            wb.Dispose();

 

        void WaitWebbrowser(WebBrowser wb)
        { 
            while(wb.IsBusy ||(wb.ReadyState != WebBrowserReadyState.Complete && wb.ReadyState != WebBrowserReadyState.Interactive ))
                Application.DoEvents();
        }

 

posted on 2015-08-21 15:42  空明流光  阅读(624)  评论(0)    收藏  举报

导航