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!
hibbsusanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.