Idea 3
Well, there is always the option to fake a delay from a non-existent server:
var running = true;
xhr.onreadystatechange = function()
{
if( !xhr.status && !xhr.readyState )
{
setTimeout( unloadTest, 250 );
}
else
{
running = false;
}
}
function unloadTest()
{
if( running )
}
Then, in another place:
window.onbeforeunload = function()
{
running = false;
}
Idea 2
Well, if below does not work, the next dom level event to test is up $(window).unloadto window.onbeforeunload. Is this a viable option?
Around your AJAX method:
var running = true;
xhr.onreadystatechange = function()
{
if( !xhr.status && !xhr.readyState && running )
{
}
else if( !xhr.status && !xhr.readyState )
{
}
running = false;
}
Then, in another place:
window.onbeforeunload = function()
{
running = false;
}
Original post (apparently not working)
Why not set a flag in the window itself?
<html>
<script type="text/javascript">
window.currentTime = new Date().getTime()
</script>
Then, when you are going to call $.ajax:
var winTime = window.currentTime;
xhr.onreadystatechange = function()
{
if( !xhr.status && !xhr.readyState && winTime == window.currentTime )
{
}
else if( !xhr.status && !xhr.readyState )
{
}
}
source
share