Seeking a way to activate the window.onbeforeunload method when a user attempts to refresh the browser, and display a message to prompt them to save their current work before leaving. I am currently working on an AngularJS application. Here is the URL of my landing page:
http:localhost:9000/#/parentPage/
Upon clicking a button, the user is directed to:
http:localhost:9000/#/parentPage/childPage1/:id
I have defined the method for loading in childPage1Ctrl:
window.onbeforeunload = function(){
return "This is a message to remind you to save your experiment before leaving the page";
};
However, upon launching the application, the onbeforeunload method is triggered.
- How can I prevent this and only bind the method to that specific page?
- Is there a way to reload a specific child page and retrieve the id from the URL?
Any assistance on these matters would be greatly appreciated.