I want to know how I can display a confirmation window when users try to exit this page, for example, here in StackOverflow, when you try to close the Ask a Question page.
Thank you in advance.
Actually, all that is needed is the following:
window.onbeforeunload = function(){ return "You should save your stuff."; }
This is also a hoax: How to show "Are you sure you want to go from this page?" when did the changes happen?
In javascript add a function to window.onbeforeunload, for example:
window.onbeforeunload
window.unbeforeunload = function (e) { // return (prompt ('Are you sure you want to exit?')); // EDIT: Amended version below: var e = e || window.event; if (e) e.returnValue = 'Your exit prompt'; return 'Your exit prompt'; }
EDIT: , . .
: window.onbeforeunload(MDC)
, : - JavaScript?, , . eventbeforeunload event
<script type="text/javascript"> window.onbeforeunload = function() { //will show a dialog asking the user if //they want to navigate away from the current page // ok will cause the navigation to continue, // cancel will cause the user to remain on the current page return "Use this text to direct the user to take action."; } </script>
: doh! , , OP: D
onbeforeunload window. , , . .
onbeforeunload
window
You can use the window.onbeforeunload event to catch this. If there is any value in the text box, a warning message is displayed.
This browser is based.
As long as you implement the tag <form>, and you enter something on the form, and in Google Chrome, it will request this message.
<form>
Source: https://habr.com/ru/post/1729021/More articles:Django General Relationship with Django Administrator - djangoSSO, Facebook connection, user merge - mergeregex - Replace all dots, special characters except file extension - c #Running a C ++ program from the Django Framework - c ++Django - проектирование отношений моделей - интерфейс администратора и встроенный интерфейс - databaseSQL Server query: SELECT 1 WHERE EXISTS and SELECT TOP 1 1 - sqlRails find - the order of presence of the Paperclip application, and then the datetime creation record - ruby-on-railsImplementing an "excellent" choice in an existing query - sqlIn Access97 SQL, how do I return a row of rows? - sqlBacklighting - openglAll Articles