Problem
Using $(window).bind("beforeunload", ...[snip] to ask if the user wants to leave the page, some strange results appear in some browsers. A dialog will appear and ask if you want to stay on the page or leave the page If you click the "Stay on the page" button, Google Chrome (the latest version is 13.0.782.215 m) and WinIE7 will display the last page of the history on the "Back" button.
To illustrate this point, the current session history consists of visiting the following pages:
You decided to get out of the fire beforeunload events. You have decided to stay on the current page.
You press the back button again and this time decide to leave the page. You should find yourself on page 2, but instead you are on page 1. However, you can again move forward to the page.
Question
How can I prevent the browser from deleting these pages from the back button when we select the option to "stay on the current page"? Is it possible?
Problem example
Using Google Chrome in a new window, go to /qaru.site / ... and look through a few questions without returning. Then click the Ask Question button. Start typing a dialog box. Click Back in your browser. Choose a stay on the page. Click again in the browser and this time select the "Leave Page" option. Now you are back two pages in history. You can essentially return to multiple pages if you click "stay on page" more than once.
Why does it matter ?!
I do not want to confuse my users. This is not a computer based approach.
My code (not so that it is relevant)
$(window).bind("beforeunload", function(){ if (in_edit > 0){ return "You are currently editing this job.\n\nAre you sure you wish to exit the page?"; } });
source share