I need to perform some interface clean-up on step 3.
How do I capture this event in Page A?
I'm going to make a few assumptions to present a way to do this that isn't fully reliant on javascript:
If both of those conditions are true, then you should be able to use a Session variable! Just set the current page into a currPage variable maintained by session on all of the related pages. Then when the page is loading, check that and use it to either adjust the way the page is shown directly, or to write a value to a hidden field/input/div, which your javascript can read and use to react appropriately.
If you go the JS-read-and-execute route, you'll want to test to ensure the events fire properly on all browsers after a load-from-back-button. As mentioned in the link from Rionmonster, sometimes onload events may not fire after a back-button. If you see issues from this, then use the tricks mentioned there to get around it.
This type of solution should work for any web-app that employs server-side code capable of interacting with Session variables (e.g. it will also work for PHP, Python, and many others).
Note: There's a chance this won't be quite as elegant as it sounds. In a lot of cases browsers may not actually pull a fresh page from the server after the back button is pressed. If testing reveals this to be an issue, you may need to employ some AJAX techniques to populate the information fresh to the JS after the back button-press.
Aside from possibly setting a cookie, you can't due to a browser security restriction. A work around would be to check if the user navigates away from the page via onbeforeunload or onunload fire.
Would it be possible in your scenario to use the URL hash to navigate to page B and use AJAX and jQuery to load the new page? Therefore, the browser is not actually leaving the page. When the user navigates back, all they will do is change the URL hash back. You could then capture the hashchange
event to see if the user has navigated back to page A.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With