问题描述
出于好奇,我可以控制window.onbeforeunload事件,如检查用户是否决定离开页面或留在其中,我可以根据他的决定提出警告或某些功能,如果有,请告诉我
From out of curiosity can i Control window.onbeforeunload event like check if the user decided to leave the page or stay in it and can I raise an alert or some function based on his decision if yes please tell me
<script type="text/javascript">
$(window).bind("beforeunload",function(){
if(//stay on page)
alert("i want to stay on the page");
else //leave page
alert("i want to leave the page");
});
</script>
我知道window.onbeforeunload是一个事件,它会给用户一条消息,告诉他也许你在你离开之前忘记做某事但是这个任务只是出于好奇并且谢谢你
I understand that window.onbeforeunload is an event that give the user a message to tell him that maybe you forget to do something before you leave but this quest is just out of curiosity and thank you
推荐答案
你无法得到 onbeforeunload 。此外,即使您以某种方式设法找到获得结果的方法,您也无法提出警报。你可以运行另一个函数。
You cannot get the result of onbeforeunload
. Also, even if you somehow managed to figure out a way to get the result, you wouldn't be able to raise an alert. You could probably run another function.
这篇关于控制window.onbeforeunload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!