最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Confirm window close - Stack Overflow

programmeradmin1浏览0评论

I am creating an HTML printable quiz and test maker and I would like to confirm "Are you sure you want to close this window?" when the user attempts to close the window. If they click ok it closes, but if they click cancel it does not.

I need this to work in IE and Chrome.

I am creating an HTML printable quiz and test maker and I would like to confirm "Are you sure you want to close this window?" when the user attempts to close the window. If they click ok it closes, but if they click cancel it does not.

I need this to work in IE and Chrome.

Share Improve this question edited Dec 11, 2013 at 6:54 Jonathan Leffler 756k145 gold badges951 silver badges1.3k bronze badges asked Mar 22, 2013 at 20:37 Dustin HDustin H 852 silver badges8 bronze badges 1
  • 4 You're probably looking for developer.mozilla/en-US/docs/DOM/window.onbeforeunload – j08691 Commented Mar 22, 2013 at 20:39
Add a ment  | 

1 Answer 1

Reset to default 5
window.onbeforeunload = function(e) {
    return 'some prompt text';
};

Working Example

发布评论

评论列表(0)

  1. 暂无评论