How does the back button work in a web browser?

I searched the Internet about this question but found nothing:

What is the logic of the back button? What happens when we click the back button in a web browser?

I really would like to know more about this.

Thank.

+79
browser back-button
Aug 21 '09 at 19:21
source share
8 answers

Your web browser stores a stack (or list, if you like) of the web pages you visited in this window. Let's say your homepage is google.com, and from there you will visit several other sites: youtube.com, yahoo.com and cnn.com. When visiting the latter, the list is as follows:

google.com -> youtube.com -> yahoo.com -> cnn.com ^ | current page 

When you click the back button, the browser will return you to the previous page in the list, for example:

 google.com -> youtube.com -> yahoo.com -> cnn.com ^ | current page 

At this point, you can click Back again to go to youtube.com, or you can click Next to send you back to cnn.com. Say you click Back a second time:

 google.com -> youtube.com -> yahoo.com -> cnn.com ^ | current page 

If you now go to, say, abc.com, the list changes as follows:

 google.com -> youtube.com -> abc.com ^ | current page 

Please note that both yahoo.com and cnn.com have disappeared from the list. This is because you have chosen a new route. The browser only supports the list of pages that you visited to get to the place where you are now, and not the history of each page that you have ever been to. The browser also does not know anything about the structure of the site you are visiting, which can lead to unexpected behavior.

You are on a shopping site (ne.com, as a brief example) that has categories and subcategories of products to view. The site designer thoughtfully provided breadcrumbs at the top of the window so you can navigate through the categories. You start on the top page of the site, click "Hardware", then "Memory". The list now looks like this:

 google.com -> ne.com -> ne.com/hw -> ne.com/hw/mem ^ | current page 

You want to return to the Equipment category so that you use breadcrumbs to go to the parent category, instead of using the Back button. Now the list of browsers is as follows:

 google.com -> ne.com -> ne.com/hw -> ne.com/hw/mem -> ne.com/hw ^ | current page 

In accordance with the structure of the site, you returned (to the level), but you went ahead to the browser because you clicked on the link. Each time you click on a link or enter a URL in the address bar, you move forward as far as the browser is concerned, regardless of whether that link leads to a page that you have already been to.

Finally, you want to return to the main page of the site (ne.com). You can use breadcrumbs, but this time you press the back button - it seems obvious that it should rise one level, right? But where does he take you?

Initially, it confuses many users (including me when I do this) that it “lowers” ​​the level and returns to the “Memory” category. If you look at the list of pages, it’s easy to see why:

 google.com -> ne.com -> ne.com/hw -> ne.com/hw/mem -> ne.com/hw ^ | current page 

To return to the main page using only the "Back" button, you will need two more clicks, taking you "back" to the "Equipment" category and, finally, to the main page. It seems to us so obvious to us programmers that this is happening, but it constantly surprises all regular users, because they do not understand that the browser does not know anything about the hierarchical structure of any website on which they are located.

Would it be nice if browsers allowed website designers to pay attention to the "Back" button to do the obvious thing (raising the level), and not what it is doing now?

Edit: The commenter asked if the browser reloads the page or simply displays it from its local cache.

The answer depends on that. Website designers can specify whether the browser should cache the page or not. For pages that are set as non-cached, the browser reloads the page from the server when you click Back, as if you had visited it for the first time. For cached pages, the browser displays it from the cache, which is much faster.

+94
Aug 21 '09 at 19:56
source share

I like to think of it as re-issuing my last request. If you performed a simple GET, it will probably return the same thing as last time (minus dynamic content). If you made a POST, you will resubmit the form (after confirmation) to the server.

+5
Aug 21 '09 at 19:25
source share

The basic idea is to return to the last page or section of a logical site.

Looking at Gmail, you’ll see if you have completed the search and click on the message, then click on the “Back” button and you will return to the search that you did.

When you click it in most browsers, it will either send the last HTTP request, or load the cache if the browser caches sites.

+2
Aug 21 '09 at 19:23
source share

I think the easiest way to explain this in pseudo code is:

 class Page: String url, ... Page previous, next # implements a doubly-linked list class History: Page current # current page void back(): if current.previous == null: return current = current.previous refresh() void forward(): if current.next == null: return current = current.next refresh() void loadPage(Page newPage): newPage.previous = current current.next = newPage # remove all the future pages current = current.next display(current) 
+2
Aug 21 '09 at 19:47
source share

The browsing history is stored as a stack. When you “type” the top three pages (for example, A, B, C) and then go to another page D, you cannot get to B again by pressing forward.

+1
Aug 21 '09 at 19:27
source share

As a devoloper, you have to make sure your webapp works no matter how the browser handles the back button :-) Does it resubmit the request? Is the new request identical to the old, or is it different in any way? Will the browser ask the user for confirmation of the repeated POST? What page elements will be re-requested and loaded from the cache? Will the browser respect my cache control headers?

The answers to this question depend on make, the browser version and user preferences. Build software so that all this does not make much difference.

Sorry for the not-so-direct answer, but there are a few direct answers here.

0
Aug 21 '09 at 20:04
source share

the browser always stores pages for remembering and when we click the "Back" button it does not send a request to the server for the previous page, but simply sees its cache where it stores pages and complies with the LIFO rule, so it gives us this page first of all when the button is clicked The "back" we opened in the last

0
Sep 02 '10 at 7:27
source share

Does the browser load the last page viewed before the current one, and then any redirection that might happen follows?

It seems that I do not see the point in the question.

-one
Aug 21 '09 at 19:24
source share



All Articles