Reputation: 7900
I am trying to invoke JavaScript method in my WebBrowser
:
WebBrowser webBrowser = new WebBrowser();
webBrowser.NavigateToString(html);
webBrowser.LoadCompleted += ((s, r) =>
{
try
{
object tmp = webBrowser.InvokeScript("GetData");
}
catch (Exception exc)
{
}
});
This is the 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>
But when i invoke the javascript with :
object tmp = webBrowser.InvokeScript("GetData");
I get Exception
:
Message:
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)
Upvotes: 3
Views: 3853
Reputation: 15268
You need to set the WebBrowser.IsScriptEnabled
to true
(it is false
by default)
Upvotes: 4