Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when I press browser BACK button?

Consider the scenario:

  1. I visited a page of a website built using ASP.NET. The page is a simple aspx page containing ASP.NET server controls.

  2. I clicked on a link which takes me to some other page on the same website.

  3. I clicked the BACK button of the browser.

QUESTION: What happens in terms of page life cycle? Does all the events occur or the browser just displays the cached version of the page without making any requests?

like image 460
Manish Avatar asked Feb 01 '10 07:02

Manish


People also ask

What event is fired when the back button of a browser is pressed?

The popstate event will be triggered by doing a browser action such as a click on the back or forward button (or calling history. back() or history. forward() in JavaScript). Browsers tend to handle the popstate event differently on page load.

What is the back button on the browser called?

In all browsers, the shortcut key combination for the back button is Alt + Left arrow key. Also, the backspace key works in many browser to go back. Tip. If you want to return to the page you came back from you can use the forward button after using the back button.

Do users use the browser back button?

And even though it's a few years old, research tells us that users are used to the browser's back button.


1 Answers

I think the best answer is: It depends on the browser, especially after a post/postback.

Older browsers used to pop up a confirmation dialog to the effect of "the page contains POST data which will be resubmitted", and you could either proceed (resubmit) or cancel out. Since everything that happens in ASP.NET WebForms is part of the FORM element (ViewState, events, etc.), this would cause the entire lifecycle to be repeated.

Of course, this caused no end of trouble with duplicate submissions, so many sites had to come up with workarounds for the dupe problem, and today most browsers just fetch the page from cache instead.

...That is unless you override the cache-control headers and force the browser not to store the page in cache. Obviously, in that case, it can't be retrieved from cache, so it will usually end up being resubmitted. But, again, it depends on the browser - for example, some browsers won't allow the resubmission over SSL, so if that's the protocol in use then the user will just see a message saying that the page has expired / can't be shown.

Come to think of it, probably an even better answer is: As a site designer, you really can't depend on any specific behaviour from the user's browser when the Back button is clicked. If a duplicate submission could have negative side-effects (such as charging a credit card twice), then you need to take adequate measures to prevent that from happening. It's good practice anyway as it's entirely possible for a user to simply double-click the "submit" button by accident.

like image 153
Aaronaught Avatar answered Sep 23 '22 22:09

Aaronaught