C#在WebBrowser中调用JavaScript
作者:互联网
我正在尝试在WebBrowser中调用JavaScript方法:
WebBrowser webBrowser = new WebBrowser();
webBrowser.NavigateToString(html);
webBrowser.LoadCompleted += ((s, r) =>
{
try
{
object tmp = webBrowser.InvokeScript("GetData");
}
catch (Exception exc)
{
}
});
这是HTML:
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title></title>
<script type="text/javascript">
function GetData ()
{
return 50;
}
</script>
但是当我用以下方式调用javascript时:
object tmp = webBrowser.InvokeScript("GetData");
我得到异常:
信息:
An unknown error has occurred. Error: 80020006.
利益追踪:
at Microsoft.Phone.Controls.NativeMethods.ValidateHResult(Int32 hr)
at Microsoft.Phone.Controls.WebBrowserInterop.InvokeScript(String scriptName, String[] args)
at Microsoft.Phone.Controls.WebBrowser.InvokeScript(String scriptName)
at YouTube.YouTubeExtractor.<>c__DisplayClass1.<ExtractVideoById>b__0(Object s, NavigationEventArgs r)
解决方法:
您需要将WebBrowser.IsScriptEnabled设置为true(默认情况下为false)
标签:windows-phone-8,wpf,javascript,c,net 来源: https://codeday.me/bug/20191123/2064425.html