Home > Web Front-end > JS Tutorial > Example of the difference between Document.location.href and .replace_Basic knowledge

Example of the difference between Document.location.href and .replace_Basic knowledge

WBOY
Release: 2016-05-16 16:57:20
Original
1057 people have browsed it

Both document.location.href and document.location.replace can switch from page A to page B, but their difference is:

After switching with document.location.href, you can return to the original page.

After switching with document.location.replace, you cannot return to the original page through "Back".

Regarding document.location.href or other reversible switching methods, I also found a detail,

Use an example to illustrate:

Suppose there is A.htm B.htm C.htm three pages

A.htm has this sentence: document.location.href="/b.htm";

b.htm has this sentence: document.location.href="/c.htm";

Note that both are reversible switches.


1: When switching from A to B and then to C, three pages are retained in the actual memory: A, B, C

2: When rolling back to B , the C page is cleared out of memory!

3: Go back again. When page A is reached, page B is also cleared from the memory!

4: When moving forward again (not by switching but by forward) to page B,

A and B are retained in the memory

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template