Problems with onbeforeunload

北战南征 提交于 2020-01-07 03:14:15

问题


I have problem with onbeforeunload and preventing user from exit the page: When user want to exits i want to redirect him on other page, without any warning or pop-up

I try to popUp that page, but browser popup detect this and block it.

Is something like that possible?

Have a nice day!


回答1:


Browsers disallow that sort of behavior since it's normally a very unpleasant thing for the user.




回答2:


Yes, i know this is unpleasant, but it is mainly internal page, so it is targeted group of users ( i hate popups to). One way i found was just redirect user on other page with message "are you realy want to leave page" (of course he want if he go away, but this is some strange fSpec)




回答3:


You can use this code: window.onbeforeunload = function() { return "MyMessage"; }



来源:https://stackoverflow.com/questions/5182299/problems-with-onbeforeunload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!