用户关闭窗口或标签时如何重定向 [英] how to redirect when user closes window or tab

查看:79
本文介绍了用户关闭窗口或标签时如何重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户关闭窗口或标签时,是否可以重定向窗口或标签?这不起作用(在jQuery中):

Is there a way to redirect the window or tab when a user closes it? This does not work (in jQuery):

$(window).bind('beforeunload', function() {
   window.location = 'anotherpage.html'
}

有可能吗?我只想在用户关闭页面时将其重定向到另一个页面.

Is it even possible? I just want to redirect a user to another page when they close it.

推荐答案

否,您唯一可以做的就是提醒用户他们即将关闭您的页面,并询问他们是否愿意留下或确认离开.

No, the only thing you can do is alert the user they are about to close your page and ask them if they would like to remain or confirm to leave.

这在要求您退出之前先保存的页面上非常普遍,例如在线考试或调查.

This is very common on pages which require you to save before exiting, like an online exam or survey for example.

  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
      return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
  }

这篇关于用户关闭窗口或标签时如何重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆