如果用户想要离开当前页面,我想弹出一条要求确认的消息,就像在输入问题时stackoverflow一样.
有人可以帮我这个,给我一个脚本或重定向我的答案(在这个网站或其他地方)?
谢谢
你可以使用这个onbeforeunload活动.
window.onbeforeunload = function() {
return 'Are you sure that you want to leave this page?';
};
Run Code Online (Sandbox Code Playgroud)