redirect to a different page
<p>I need some help here:</p>

<p>I am writing code to redirect a user to a different page and execute some code, if the user closes the window while he is working on something:</p>

<pre><code>&lt;script type="text/javascript"&gt;
     window.onbeforeunload = function() {
         location.assign('http://www.somesite.com');
         return "go?";
     }
&lt;/script&gt;
</code></pre>

<p>Now the code works fine if the user presses cancel. But if he presses Ok, the windows closes without a redirect. </p>

<p>I just need a working code that does one simple thing - redirect the user if the window is closed - can anyone suggest me the code for it</p>

<p>I know that most of you will say that I should not be doing this and I know that this is not the best practice. But if any one of you has written a successful piece of code, please share it here.</p>
