run javascript when opening another page
<p>I'd like to open another web page from javascript (like default navigating, not fullscreen iframe or window.open) and run some javascript code upon loading it.</p>

<p>Steps:</p>

<ol>
<li>Define a javascript function</li>
<li>Navigate to another page</li>
<li>Browser runs function in new page context</li>
</ol>

<p>is there any way to achieve this? the only way I remember would be emulating this by loading the page using ajax, and replacing document.body.innerHtml, then running the function, but that would not change location.href, so e.g. the back button or bookmarks wouldn't work. also relative links had to be rewritten at loading, etc...</p>

<p>PS: I know that would be some ugly XSS, but it's needed for example when writing bookmarklets that load a page and fill in a form automatically.</p>
