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(); }