简体   繁体   中英

How to display the dialog before leaving the page with JQuery

I want to make my app display the dialog always before leaving the page. I'm trying to use event beforeunload but it display the dialog only if i do some changes on the webpage. If i just open the page and then leave it dialog is not displayed...

$(window).on('beforeunload', function(){
    return "";
});

The document is well explained, so I link it.

To combat unwanted pop-ups, browsers may not display prompts created in beforeunload event handlers unless the page has been interacted with, or may even not display them at all.

https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM