title: Wpf WebBrowser load javascript
body: <p>I have this <code>WebBrowser</code> in my page:</p>
  
  <pre><code>&lt;WebBrowser HorizontalAlignment="Stretch" Name="Browser"
              VerticalAlignment="Stretch" Grid.Column="1"/&gt;
  </code></pre>
  
  <p>Now after i load a page i want to inject a <code>JavaScript</code> code with :</p>
  
  <pre><code>var doc = (HTMLDocument)Browser.Document;
  var head = doc.getElementsByTagName("head").Cast&lt;HTMLHeadElement&gt;().First();
  var script = (IHTMLScriptElement)doc.createElement("script");
  script.text = MYSCRIPTCODE;
  head.appendChild((IHTMLDOMNode)script);
  </code></pre>
  
  <p>And in <code>MYSCRIPTCODE</code> i have this function:</p>
  
  <pre><code>function checkSomething() {
  
      try{
             var xhr = new XMLHttpRequest();
             var url = 'weburl';
             xhr.open("GET", url, true);
             xhr.onreadystatechange = function () {
             //Somecode
             }
  
             xhr.send();
      } catch {
  
      }
  }
  </code></pre>
  
  <p>And i run it with:</p>
  
  <pre><code>Browser.InvokeScript("checkSomething");
  </code></pre>
  
  <p>It's work perfect and run the script without any problem.</p>
  
  <p>I have another state that i load local html file to the browser:</p>
  
  <pre><code>Uri uri = new Uri(AppDomain.CurrentDomain.BaseDirectory + @"OfflinePage.html");
  Browser.Navigate(uri);
  </code></pre>
  
  <p>And when i want to run it with :</p>
  
  <pre><code>Browser.InvokeScript("checkSomething");
  </code></pre>
  
  <p>This line in the script get exception - Permission Denied:</p>
  
  <pre><code>xhr.open("GET", url, true);
  </code></pre>
  
  <p>Any idea why it happen? why it work in a page that i load from web and won't work in a local html?</p>