Browser/tab close detection using javascript (or any other language)

后端 未结 3 1127
感情败类
感情败类 2020-12-10 23:00

I searched for this question in various places, but all that they mention is the use of javascript window.unload & window.onbeforeunload. Also it doesn\'t

3条回答
  •  没有蜡笔的小新
    2020-12-10 23:53

    If you only want to ask a user if they want to leave the page when they've changed anything in the forms on the page, have a look at PageHasFormChanges. Keep in mind that I developed it for use it on very simple pages, with only one or two forms.

    PageHasFormChanges: A jQuery plugin to check if anything has changed in any form on a page, and warn the user before leaving the page.

    You don't need to do anything, but load the script on your page. You can change the defaults though:

    JoelPurra.PageHasFormChanges.setOptions({
        leavingPageWarningMessage: "Are you sure?"
    });
    

    If you're using ajax to submit your forms, you could consider setting resetWarningOnPreventedSubmit to true.

提交回复
热议问题