我正在尝试在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");
我得到Exception
:
消息:
An unknown error has occurred. Error: 80020006.
StakeTrace:
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)
答案 0 :(得分:3)
您需要将WebBrowser.IsScriptEnabled
设置为true
(默认为false
)