Home > Web Front-end > JS Tutorial > Comparison of href and replace in javascript (detailed explanation)

Comparison of href and replace in javascript (detailed explanation)

高洛峰
Release: 2017-01-04 13:30:41
Original
1427 people have browsed it

When using JavaScript, sometimes we are too familiar with frequently used methods and ignore the subtle differences in principles between them.

Examples are as follows:

window.location.href, window.location.replace.

Both of these methods can make the page jump to a new page, but I ignored the details after the jump, such as the original page returned.

The href in window.location.href is actually the href in the tag. After using this to jump to the page, you can use the browser's back button to return to the original page, or you can use history The .go(-1) function jumps to the original page.

window.location.replace(url) method allows the browser to clear the URL in its history and reset the URL. When using the browser's back button or forward button, it will not be able to jump to the original page, but will jump to the previous page of the original page.

That is, the replace() method will not generate a new record in the History object. When using this method, the new URL will overwrite the current record in the History object.

The above comparison of href and replace in javascript (detailed explanation) is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.

For more related articles on the comparison of href and replace in javascript (detailed explanation), please pay attention to the PHP Chinese website!


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