admin管理员组文章数量:1415146
I'm looking for an function that shows a alertbox when the visitor is trying to leave the page when he or she haven't finished the form. I have imported an image to show what I mean. Translation: title = "Confirm navigation", content = "Do you want to leave this page?", button1 = "Leave this page", button2 = "Stay on this page".
Facebook uses this alertbox when you want to go back one page when you have for example not finished an PM to someone.
How can I acplish something like this?
Thanks in advance.
I'm looking for an function that shows a alertbox when the visitor is trying to leave the page when he or she haven't finished the form. I have imported an image to show what I mean. Translation: title = "Confirm navigation", content = "Do you want to leave this page?", button1 = "Leave this page", button2 = "Stay on this page".
Facebook uses this alertbox when you want to go back one page when you have for example not finished an PM to someone.
How can I acplish something like this?
Thanks in advance.
Share Improve this question asked Feb 24, 2012 at 3:07 AirikrAirikr 6,44615 gold badges64 silver badges112 bronze badges1 Answer
Reset to default 4Use window.onbeforeunload
in conjunction with a flag that gets set when a change is made to a form field.
For example:
var changed_flag = 0; // change in an onchange event or whatever, something like the below
document.getElementById('form_field').onchange = function() {
changed_flag = 1;
};
window.onbeforeunload = function() {
if ( changed_flag ) {
return 'You have unsubmitted changes.'
}
};
本文标签: javascriptquotConfirm navigationquot alertboxStack Overflow
版权声明:本文标题:javascript - "Confirm navigation" alertbox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745222081a2648440.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论