简体   繁体   中英

How to get the "Leave site? Changes that you made may not be saved" when trying to close a window with a populated form

I have a form that when filled in, I can exit the window without being given a warning (I'm using Chrome).

How can I ensure I get a warning before exiting? Is there a Django setting for this?

您需要提供一个函数,返回一个字符串到onbeforeunload窗口或文档正文,以触发“离开站点”弹出窗口。

 window.onbeforeunload = () => '';
 <a href="http://example.com">Click to trigger</a>

该事件称为beforeunload,因此您可以为window.onbeforeunload分配一个函数

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