jQuery的提示保存数据onbeforeunload [英] jquery prompt to save data onbeforeunload
问题描述
我要提醒用户导航远离他们(通过点击页面上的其他链接)使用jQuery UI的对话框之前,以节省某些网页的数据。我知道我需要使用onbeforeunload事件来检测用户离开当前页面,则显示该对话框。但是,我怎么可以导航的继续选定的URL,当用户点击是,在对话框中,并留在当前页面,当用户点击否?
I want to remind users to save data on certain pages before navigating away from them (by clicking other links on the page) using the jquery ui dialog box. I know I need to use the onbeforeunload event to detect that a user is leaving the current page, then display the dialog. However, how do I allow navigation to continue to the selected url when the user clicks "Yes" on the dialog box, and stay on the current page when the user clicks "No"?
谢谢!
推荐答案
您只需要分配具有提示功能的 window.onbeforeunload 的事件,例如:
You just need to assign function with prompt to window.onbeforeunload event, e.g.:
window.onbeforeunload =
function() {
return "Please make sure your data is saved."
}
和浏览器会自动提示有2个选择用户:离开此页和留在这个页面上的
And the browser will automatically prompt the user with 2 choices: "Leave this page" and "Stay on this page"
这篇关于jQuery的提示保存数据onbeforeunload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!