When does javascript stop running on a page after a link is clicked?
<p>I have a page which runs various javascript code, including calling <code>setTimeout()</code>. If a user clicks a link to navigate to another page, at what point does the javascript on this page stop running and therefore my code called by setTimeout will no longer be called? e.g.</p>

<ul>
<li>as soon as the link is clicked (I know this is wrong)</li>
<li>when the browser starts receiving the new page</li>
<li>some other point?</li>
</ul>

<p>And is this different for the different major browsers?</p>

<p><strong>Background</strong></p>

<p>I want to know this largely for interest's sake rather than to solve any particular problem. The problem which prompted me to think about this is I'd like to do something when a user clicks a particular link on a page. I want to perform an ajax call and process the result, but I'm not too concerned if it finishes before the page is unloaded. So I'll fire a setTimeout() on the link click and then if I'm lucky it'll finish but if I'm not it won't. I wondered in what circumstances it'll work. While there may be other solutions to that problem, I don't want solutions to the problem I only want to know the answer to the question. </p>
