title: C# WebBrowser InvokeScript gives error
body: <p>I am developing Windows Phone 7.5 PhoneGap app. I needed to call JavaScript function from code behind C#. My MainPage.xaml.cs is follows.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Animation;
  using System.Windows.Shapes;
  using Microsoft.Phone.Controls;
  using System.IO;
  using System.Windows.Media.Imaging;
  using System.Windows.Resources;
  
  
  
  namespace MFMA
  {
      public partial class MainPage : PhoneApplicationPage
      {
          WebBrowser webBrowser = new WebBrowser();
  
          // Constructor
          public MainPage()
          {
              InitializeComponent();
              this.CordovaView.Loaded += CordovaView_Loaded;
          }
  
          private void CordovaView_Loaded(object sender, RoutedEventArgs e)
          {
              this.CordovaView.Loaded -= CordovaView_Loaded;
              // first time load will have an animation
              Storyboard _storyBoard = new Storyboard();
              DoubleAnimation animation = new DoubleAnimation()
              {
                  From = 0,
                  Duration = TimeSpan.FromSeconds(0.6),
                  To = 90
              };
              Storyboard.SetTarget(animation, SplashProjector);
              Storyboard.SetTargetProperty(animation, new PropertyPath("RotationY"));
              _storyBoard.Children.Add(animation);
              _storyBoard.Begin();
              _storyBoard.Completed += Splash_Completed;
          }
  
          void Splash_Completed(object sender, EventArgs e)
          {
              (sender as Storyboard).Completed -= Splash_Completed;
              LayoutRoot.Children.Remove(SplashImage);
          }
  
          private void OnClearCookies(object sender, EventArgs e)
          {
              this.webBrowser.IsScriptEnabled = true;
              this.webBrowser.InvokeScript("clearCookies");
  
  
  
  
          }
      }
  }
  </code></pre>
  
  <p>The following is the index.html.</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt; 
  &lt;html&gt; 
      &lt;head&gt; 
  
          &lt;meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1,initial-scale=1"&gt;
          &lt;title&gt;MFMA&lt;/title&gt; 
          &lt;link rel="stylesheet" href="css/jquery.mobile-1.3.1.css" /&gt;
          &lt;link rel="stylesheet" href="css/jquery.mobile.structure-1.3.1.css" /&gt;
  
          &lt;Script type="text/javascript" src="js/jquery-2.0.0.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="js/jquery.mobile-1.3.1.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="cordova-2.4.0.js"&gt;&lt;/script&gt;
           &lt;script type="text/javascript" src="js/index.js"&gt;&lt;/script&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div data-role="page" id="interfacePage" class="page-bg" style="background: rgb(64,150,194) url(Icons/background_mobile.png) no-repeat center center;
      background-position: 0% 90%;background-size:100%; -webkit-background-size: cover; -moz-background-size: cover;
      -o-background-size: cover; background-size: cover;background-attachment:fixed"&gt;
              &lt;div data-role="content" &gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="app"&gt;
              &lt;h1&gt;Apache Cordova&lt;/h1&gt;
              &lt;div id="deviceready" class="blink"&gt;
                  &lt;p class="event listening"&gt;Connecting to Device&lt;/p&gt;
                  &lt;p class="event received"&gt;Device is Ready&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;script type="text/javascript"&gt;
              app.initialize();
              document.addEventListener("deviceready", onDeviceReady, false);
              function onDeviceReady() {
  
                  console.log('start!!!!!!!!!!!!!!!!!!!!!!!!!!');
                  var url;
                  if (typeof (window.localStorage) == 'undefined') {
                      console.log('local storage not defined');
                  }
                  if (typeof (window.localStorage) != 'undefined') {
                      console.log('getting item');
                      url = window.localStorage.getItem("url");
                      console.log('saved URL is ' + url);
                  }
                  //var url = getCookie("url");
                  if (url != null &amp;&amp; url != "") {
                      window.location.href = 'http://' + url;
                  } else {
                      window.location.href = 'index1.html';
                  }
              }
  
              function clearCookies() {
                  //console.log("success!!!!!!!!!!!!!!!");
                  window.localStorage.removeItem('url'); 
              }
  
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am getting "<code>An unknown error has occurred. Error: 80020006.</code>" May I know how to fix this. I already went through forums and Stack Overflow. I could not get a solution.</p>