title: Using Javascript to Open a New Page and Populate Form Values There
body: <p>I am using JavaScript in a bookmarklet to populate form elements on a website:</p>
  
  <pre><code>javascript:var f = document.forms[0];
  f.getElementsByTagName('input')[0].value = 'myname';
  f.getElementsByTagName('input')[1].value = 'mypassword';
  f.getElementsByTagName('input')[2].click
  </code></pre>
  
  <p>This works. However what I would like to create is a bookmarklet so that it opens the target page, and populates the values there; however it seems that onces the page is loaded, other JavaScript codes are not executed. So, the following doesn't work.</p>
  
  <pre><code>javascript:window.location("mywebsite");var f = document.forms[0];
  f.getElementsByTagName('input')[0].value = 'myname';
  f.getElementsByTagName('input')[1].value = 'mypassword';
  f.getElementsByTagName('input')[2].click;
  </code></pre>
  
  <p>I have also experimented with setTimeout to delay the execution of my code, but that didn't work.</p>
  
  <pre><code>javascript:var f = document.forms[0];setTimeout("f.getElementsByTagName('input')[0].value = 'myname';f.getElementsByTagName('input')[1].value = 'mypassword';f.getElementsByTagName('input')[2].click;",1000);
  </code></pre>
  
  <p>How can I load my script once I know the target page is fully loaded?</p>