Delay close with javascript?

Now I understand that bad practice delays page closure and that there are more efficient ways to handle this kind of thing, but only for future reference, is there a way to delay page closure? Sort of

window.onunload = unload();

function unload()
{
setTimeout("self.close()", 1000)
}

Thank!

+5
source share
1 answer

If you really need (i.e., you're ready to resort to half-hacks) to delay closing the page without showing a confirmation dialog, etc., you can do something like the following:

function delay(ms) {
    var start = +new Date;
    while ((+new Date - start) < ms);
}

// start image loading (I assume you need this for tracking?)
delay(150);

: , . , 95% ( ).

+9

All Articles