简体   繁体   中英

window.onunload fires and then the user clicks stop

Here is the flow I am trying to figure out.

  • User hits my page.
  • User clicks a link and onbeforeunload and unload get fired. Here i am getting rid of href in some of my links.
  • The page now hangs for a little bit giving the user a chance to hit the stop button in the browser.
  • Since the page is still on the original page (not the new page that was requested and then stopped) the hrefs are still blank.

Is there any way of knowing if the user clicks a stop button and they are still on the same page?

The only way I can think off the top of my head is to put a setTimeout in the onbeforeunload or unload but I don't really like that because there are too many variables for it still being messed up.

What I ended up doing was this:

window.unload = function(){
    var _href = $('selector').attr('href');
    $('selector').attr('href', '');

    setTimeout(function(){
        $('selector').attr('href', _href);
    }, 1500);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM