hibbsusan
asked on
forward/back buttons don't show confirm "are you sure you want to leave"
Hello!
A while back I asked if there were anyway to ask a user if he or she were sure they wanted to leave a page by showing an alert if anything but the confirm button were pressed. User leakim971 kindly posted this solution:
It works really well, but I wonder if there is anyway to prevent showing the alert on browser "forward" / "back" button presses (?)
Thank you very much!
A while back I asked if there were anyway to ask a user if he or she were sure they wanted to leave a page by showing an alert if anything but the confirm button were pressed. User leakim971 kindly posted this solution:
<input type="button" onclick="stopit=false;" value="Order" />
<script language="JavaScript">
var stopit = true;
window.onbeforeunload = confirmExit;
function confirmExit()
{
if( stopit ) {
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
}
</script>
It works really well, but I wonder if there is anyway to prevent showing the alert on browser "forward" / "back" button presses (?)
Thank you very much!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No, that is a browser functionality object and not part of the rendered page. Sorry.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
is there anyway to add a line to this code to make it scroll to the bottom of the page as well. To <a href="#confirmation"></a> ?
<a href="#confirmation"></a> will move the browser's scroll to focus the anchor or element with the ID "confirmation". Making that link scroll to the bottom as well defeats the purpose of having it navigate to "#confirmation".
ASKER
I'm sorry...that was sort of redundant. I just want it to return the confirm box like it already does, and if the user decides to stay on the page, to scroll to the anchor #confirm
Does that make sense?
Thanks!
Leakim-
I will check out that article soon as I am back to a proper computer.
Thanks!
Does that make sense?
Thanks!
Leakim-
I will check out that article soon as I am back to a proper computer.
Thanks!
ASKER