• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

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:

<input type="button" onclick="stopit=false;" value="Order" />

Open in new window


<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>

Open in new window


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!
0
hibbsusan
Asked:
hibbsusan
  • 3
  • 3
2 Solutions
 
strickddCommented:
No, this is a built-in javascript functionality that detects when navigating to a page other than the current page. When Forward/Back are clicked, the browser fires the onbeforeunload event.
0
 
hibbsusanAuthor Commented:
So is there no way to not show the alert when forward back buttons are pressed? Even with a new script?
0
 
strickddCommented:
No, that is a browser functionality object and not part of the rendered page. Sorry.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
hibbsusanAuthor Commented:
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> ?
0
 
strickddCommented:
<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".
0
 
hibbsusanAuthor Commented:
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!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now