当用户关闭窗口或标签时,有没有办法重定向?这不起作用(在jQuery中):
$(window).bind('beforeunload', function() {
window.location = 'anotherpage.html'
}
Run Code Online (Sandbox Code Playgroud)
它甚至可能吗?我只是想在用户关闭它时将用户重定向到另一个页面.
不,您唯一能做的就是提醒用户他们即将关闭您的页面并询问他们是否愿意留下或确认离开.
这在需要您在退出之前保存的页面上非常常见,例如在线考试或调查.
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?";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1716 次 |
| 最近记录: |