How to change the text of “Are you sure you want to leave this page?” function script of “onunload”?

血红的双手。 提交于 2019-12-08 13:45:25

问题


How to change the text of this function script?:

window.onbeforeunload = function(e) { return 'Are you sure you want to leave this page? You will lose any unsaved data.'; };

i want to translate the text " 'Are you sure you want to leave this page? You will lose any unsaved data.' " so it can say the same but in my language... how to do it? Please help - thanks

(when i translate it, it doesnt change in the frontend). Thanks in advance guys!


回答1:


unfortunately, changing the message seems to only work in Internet Explorer (see w3schools). I don't think you'll be able to insert blocking code either(such as alert()), as it would be a security breach for the browser).




回答2:


also how to make the function be "on" for all external pages and be disabled for any inside pages like "domain.com -> domain.com/about-us" ?



来源:https://stackoverflow.com/questions/41812552/how-to-change-the-text-of-are-you-sure-you-want-to-leave-this-page-function-s

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