Reputation: 83
detect_reload() function will produce a message if webpage is reloaded by user.
What should be code for detect_reload() function?
function detect_reload()
{
}
Upvotes: 0
Views: 92
Reputation: 8423
When the page HAS been reloaded, not before:
Maybe you could use document.referrer
for this?
$(function() {
if(document.referrer === "") {
//Your code here
}
});
Upvotes: 0
Reputation: 242
Check the following link. https://stackoverflow.com/a/10400239/3184797 It has stated that
If it is refreshing, window.onunload will fire.
// From MDN
window.onunload = unloadPage;
function unloadPage()
{
alert("unload event detected!");
}
https://developer.mozilla.org/en/DOM/window.onunload
If you just want a confirmation box to allow them to stay, use this:
window.onbeforeunload = function() {
return "Are you sure you want to navigate away?";
}
Upvotes: 3