简体   繁体   English

window.onunload 触发,然后用户单击停止

[英]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.用户单击链接并触发onbeforeunloadunload Here i am getting rid of href in some of my links.在这里,我在一些链接中摆脱了 href。
  • 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.由于页面仍然在原始页面上(不是请求然后停止的新页面),hrefs 仍然是空白的。

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.我能想到的唯一方法是在onbeforeunloadunload中放置一个 setTimeout ,但我真的不喜欢这样,因为变量太多,它仍然被搞砸了。

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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