Web 浏览器中的后退按钮如何工作? [英] How does the Back button in a web browser work?

查看:33
本文介绍了Web 浏览器中的后退按钮如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了这个问题,但一无所获:

I searched the Web about this question but I found nothing:

后退按钮的逻辑是什么?当我们点击 Web 浏览器上的后退按钮时会发生什么?

What is the logic of the back button? What is happening when we hit the back button on a Web browser?

我真的很想了解更多.

谢谢.

推荐答案

您的 Web 浏览器会在该窗口中保留您访问过的网页的堆栈(或列表,如果您愿意).假设您的主页是 google.com,然后您从那里访问其他几个网站:youtube.com、yahoo.com 和 cnn.com.访问最后一个时,列表如下所示:

Your web browser keeps a stack (or list, if you will) of the web pages that you have visited in that window. Let's say your home page is google.com and from there you visit a few other websites: youtube.com, yahoo.com, and cnn.com. Upon visiting the last one, the list looks like this:

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

当您按下后退按钮时,浏览器会将您带回列表中的上一页,如下所示:

When you press the Back button, the browser takes you back to the previous page in the list, like this:

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

此时您可以再次按返回"将您带到 youtube.com,或者您可以按前进"再次将您带到 cnn.com.假设您再次按返回":

At this point you can press Back again to take you to youtube.com, or you can press Forward to put you at cnn.com again. Let's say you press Back a second time:

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

如果您现在访问 abc.com,列表将变为如下所示:

If you now go to, say, abc.com, the list changes to look like this:

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

注意 yahoo.com 和 cnn.com 都从列表中消失了.这是因为你走了一条新路.浏览器仅维护您访问过的页面以到达您现在所在的位置的列表,而不是您曾经访问过的每个页面的历史记录.浏览器也不知道您正在访问的网站的结构,这可能会导致一些令人惊讶的行为.

Note that both yahoo.com and cnn.com are gone from the list. This is because you took a new route. The browser only maintains a list the pages you visited to get to where you are now, not a history of every page you've ever been to. The browser also doesn't know anything about the structure of the site you're visiting, which can lead to some surprising behavior.

您正在访问一个购物网站(以 ne.com 为例),该网站包含可供浏览的产品类别和子类别.网站设计者在窗口顶部附近提供了面包屑,以便您浏览类别.您从站点的首页开始,单击硬件,然后单击内存.该列表现在看起来像这样:

You're on a shopping site (ne.com, as a short example) that has categories and subcategories of products to browse through. The site designer has thoughtfully provided breadcrumbs near the top of the window to allow you to navigate through the categories. You start at the top page of the site, click on 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 go back to the Hardware category, so you use the breadcrumbs to go up to the parent category instead of using the Back button. Now the browser list looks like this:

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

根据站点结构,您向后退(上一级),但在浏览器中您前进了,因为您单击了链接.每当您点击链接或在地址栏中输入网址时,就浏览器而言,您都在前进,无论该链接是否将您带到您已经访问过的页面.

According to the site structure, you went backward (up a level), but to the browser you went forward because you clicked on a link. Any time you click on a link or type in a URL in the address bar, you are going forward as far as the browser is concerned, whether or not that link takes you to a page that you've already been to.

最后,您要返回主站点页面 (ne.com).您可以使用面包屑导航,但这次您单击后退"按钮——很明显它应该让您上升一个级别,对吗?但它带你去哪里?

Finally, you want to return to the main site page (ne.com). You could use the breadcrumbs, but this time you click the Back button -- it seems obvious that it should take you up one level, right? But where does it take you?

最初让许多用户(包括我自己,当我碰巧这样做时)感到困惑的是,它会将您下"一个级别,回到内存"类别.查看页面列表,很容易看出原因:

It's initially confusing to many users (myself included, when I happen to do exactly this) that it takes you "down" a level, back to the Memory category. Looking 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 go back to the main page using only the Back button would require two more presses, taking you "back" to the Hardware category and finally to the main page. It seems so obvious to us programmers what's going on, but it surprises the heck out of regular users all the time because they don't realize that the browser doesn't know anything about the hierarchical structure of whatever website they happen to be on.

如果浏览器允许网站设计者对后退按钮进行编程以执行显而易见的事情(让您提升一个级别)而不是现在所做的任何事情,那会很棒吗?

Would it be great if browsers would let site designers program the Back button to do the obvious thing (take you up a level) rather than whatever it does now?

评论者询问浏览器是重新加载页面还是只是从本地缓存中显示它.

A commenter asked whether the browser reloads the page or simply displays it out of its local cache.

答案是视情况而定.网站设计者可以指定浏览器是否应该缓存页面.对于设置为非缓存的页面,当您按返回"时,浏览器会从服务器重新加载页面,就好像这是您第一次访问它一样.对于缓存页面,浏览器将其从缓存中显示出来,这样会快很多.

The answer is it depends. Site 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 press Back, as though it was the first time you are visiting it. For cached pages, the browser displays it out of the cache, which is much faster.

这篇关于Web 浏览器中的后退按钮如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆