I work on Javascript and I have a simple page.I need to prompt message appear when user want to refresh the page(F5, so on). Is there any method to do so?
I have tried to use method="post", but because I dont submit anything in my page it doesnt work at all.
Most of the time users want to disable prompt message, but what to do if I want to appear it?
Alert message?
Any ideas?
Asked
Active
Viewed 3,527 times
0
rene
- 39,748
- 78
- 111
- 142
user2082503
- 99
- 1
- 9
-
@rene You were faster finding a duplicate than I writing this short answer. :) – insertusernamehere Sep 09 '13 at 18:07
-
@insertusernamehere sorry, give me a call next time and I'll move on...:) Nice demo... – rene Sep 09 '13 at 18:10
1 Answers
2
You can use window.onbeforeunload. The user will be prompted your message and he has the possibility to stay or to leave.
JavaScript
window.onbeforeunload = function(e) {
return "Don't leave";
};
Demo
Learn more on the MDN window.onbeforeunload
insertusernamehere
- 22,497
- 8
- 84
- 119