3

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)
1

1 Answer 1

4

You need to set the WebBrowser.IsScriptEnabled to true (it is false by default)

Sign up to request clarification or add additional context in comments.

1 Comment

That is not a property for the WPF WebBrowser control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.