The difference between location.href and Location.replace and Location.reload (Location.replace does not record history)

Source: Internet
Author: User
Tags server memory

Location.href

Iframe.location.href

window.location.href
Entire URL string (in the browser is the complete address bar)

Reloadmethod, which forces the browser to refresh the current page.
Syntax: Location.reload ([Bforceget])
Parameters: Bforceget, optional parameter, default to False, take the current page from the client cache. True to get the latest page from the service, equivalent to the client-click F5 ("Refresh")
Replacemethod, which replaces the item currently cached in history (the client) by specifying a URL, so after you use the Replace method, you cannot access the URL that has been replaced by "forward" and "back".
Syntax: Location.replace (URL)
Parameters: URL
In practical applications, when refreshing the page, we usually use: Location.reload () or History.go (0). Because this practice is like the client point F5 Refresh the page, so the page method= "POST", will appear "page expiration" hint. That's because the session's security protection mechanism. It can be thought that when the Location.reload () method is invoked, the ASPX page already exists in the server memory, so it must be IsPostback.
If this applies: we need to reload the page, which means we expect the page to be recreated on the server side, and we expect it to be not IsPostback. Here, Location.replace () can complete this task. The replaced pages are regenerated each time on the server side. You can write this: Location.replace (location.href)

and redirection uses theHerfAndReplace
<script type= "Text/javascript" >
location.href= ' http://www.xxx.com/';
</script>

<script type= "Text/javascript" >
Location.replace (' http://www.xxx.com/');
</script>

The difference is that the former adds a new record to the browser's historical browsing record (History object), which is equivalent to replacing the existing page URL with the URL in replace and replacing the URL in history with the redirected URL.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.