An example of the difference between document.location.href and.replace

  • 2020-03-30 02:13:12
  • OfStack

Document. The location. The href and document. The location. The replace can realize the switch from A page to page B, but their difference is:

After switching to document.location.href, you can go back to the original page.

With the document. The location. The replace after switching, may not use a "back" back to the original page.

I also found one detail about document.location.href or some other fallback toggle,

Here's an example:

Suppose there are three pages of a.htm, b.htm, c.htm

Document.location.href ="/b.htm";

In b.htm there is a sentence like this: document.location.href="/c.htm";

Note that both are returnable switches.


1: when switching from A to B and then to C, there are three pages in the real memory: A, B and C

2: back to B, C page is out of memory!

3: back again, to A page, B page is also cleared out of memory!

4: when I move forward again (not by switching, but by moving forward) to page B,

The only things left in memory are A and B

> > > When a document is replaced by location.replace (), it is removed from the current history object

Related articles: