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 4,903 times
1

rene
- 41,474
- 78
- 114
- 152

user2082503
- 109
- 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
3
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
- 23,204
- 9
- 87
- 126