I'm in the process of creating a web page that allows for remote control of a microcontroller, and I'm looking to build in a feature that requires a user to confirm that they would like to leave the page if they try to navigate away from the control site. I don't want to use the confirm() method, but would rather like to have a popup window appear with two buttons ("Leave the site", "Return to site") that control the action of the main window.
As of right now, I've been able to create the popup window but am stuck on trying to control the navigation of the main window. Is there any method that would allow me to pause the pending navigation to another page in order for the popup to execute first and then have the main window respond? Another alternative would be to somehow grab the address the user wants to view, store that in a variable, and then access that variable in the popup...I tried that as well to no avail.
Additionally, it seems as though simply closing either the tab or the main window (in IE and Firefox) completely bypasses my popup command. Is there any way to prevent that from happening?
Here is the code that I'm using for my main page:
XXXXXXX //irrelevant custom code for control
navigate("/failsafe.html", "exit", "width=800px, height=600px")
And here's my popup code:
<input type="button" value="Leave the Control Webpage" onclick="window.close()" />
<input type="button" value="Return to the Control Webpage" onclick="window.navigate('/saavtest.html')" />