title: Hijacking a variable with a userscript for Chrome
body: <p>I'm trying to change the variable in a page using a userscript.
  I know that in the source code there is a variable </p>
  
  <pre><code>var smilies = false;
  </code></pre>
  
  <p>In theory I should be able to change it like that:</p>
  
  <pre><code>unsafeWindow.smilies = true;
  </code></pre>
  
  <p>But it doesn't work. When I'm trying to alert or log the variable to the console without hijacking I get that it's undefined.</p>
  
  <pre><code>alert(unsafeWindow.smilies); // undefined !!!
  </code></pre>
  
  <p><strong>EDIT: I'm using Chrome if it changes anything...</strong></p>
  
  <p><a href="http://code.google.com/chrome/extensions/content_scripts.html" rel="noreferrer">http://code.google.com/chrome/extensions/content_scripts.html</a> says:</p>
  
  <blockquote>
    <p>Content scripts execute in a special environment called an isolated
    world. They have access to the DOM of the page they are injected into,
    but not to any JavaScript variables or functions created by the page.
    It looks to each content script as if there is no other JavaScript
    executing on the page it is running on.</p>
  </blockquote>
  
  <p>It's about Chrome Extensions but I guess it's the same story with Userscripts too?</p>
  
  <p>Thank you, Rob W. So the working code for people who need it:</p>
  
  <pre><code>var scriptText = "smilies = true;";
  var rwscript = document.createElement("script");
  rwscript.type = "text/javascript";
  rwscript.textContent = scriptText;
  document.documentElement.appendChild(rwscript);
  rwscript.parentNode.removeChild(rwscript);
  </code></pre>