Summary of differences between refreshing location. reload and location. replace on the js page

Source: Internet
Author: User

First, we will introduce the syntax of the two methods:
Reload method, which forces the browser to refresh the current page.
Syntax: location. reload ([bForceGet])
Parameter: bForceGet. An optional parameter. The default value is false. The current page is retrieved from the client cache. True, the GET method is used to obtain the latest page from the server, which is equivalent to clicking F5 ("refresh") on the client ")

Replace MethodThis method replaces the items currently cached in the History (client) by specifying the URL. Therefore, after the replace method is used, you cannot access the replaced URL by "Forward" or "backward.
Syntax: location. replace (URL)
When refresh the page in practice, we usually use location. reload () or history. go (0. This method is like refreshing the page by pressing F5 on the client. When the method = "post" is displayed, the prompt "webpage expired" appears. This is because of the security protection mechanism of the Session. It can be thought of: when the location. reload () method is called, The aspx page already exists in the server memory, so it must be IsPostback. If there is such an application: we need to re-load the page, that is, we expect the page to be re-created on the server, and we expect it to be Not IsPostback. Here, location. replace () can complete this task. The page to be replaced is generated on the server every time. You can write: location. replace (location. href)

The following are related applications and knowledge points:
Window. location. href
Window. top. location. replace ("http://www.jb51.net ")
Top. location. href ("http://www.jb51.net ")
Window. navigate ("http://www.jb51.net ")
Html:
<Meta http-equiv = "Refresh" content = "0; url = http://baidu.com/">
---------------------------------------
URL: Uniform Resource Locator (Uniform Resource Locator, URL)
The complete URL consists of the following parts:
Scheme: // host: port/path? Query # fragment
Scheme: Communication Protocol
Common http, ftp, maito, etc.
Host: host
The host name or IP address of the server (Computer) Domain Name System (DNS.
Port: port Number
INTEGER (optional) Default port used when the scheme is omitted. For example, the default port of http is 80.
Path: path
A string separated by zero or multiple "/" symbols. It is generally used to represent a directory or file address on the host.
Query: query
Optional. Used for dynamic web pages (such as CGI, ISAPI, PHP/JSP/ASP. NET and other technologies to produce web pages) transmission parameters, can have multiple parameters, separated by the "&" symbol, each parameter name and value are separated by the "=" symbol.
Fragment: Information fragment
String used to specify fragments in network resources. For example, if a webpage contains multiple glossary, you can use fragment to directly locate the glossary. (Also called anchor .)
For such a URL
Http://www.jb51.net: 80/fisker/post/0703/rows configurlocation.html? Ver = 1.0 & id = 6 # imhere

We can use javascript to obtain all the parts.
1, window. location. href
The whole URl string (the complete address bar in the browser)
Returned value in this example: http://www.jb51.net: 80/fisker/post/0703/optional parameter location.html? Ver = 1.0 & id = 6 # imhere
2, window. location. protocol
URL protocol section
Returned value in this example: http:
3, window. location. host
Host part of the URL
Returned value in this example: www.jb51.net
4, window. location. port
URL Port
If the default port 80 is used (update: Even if port 80 is added), the return value is not the default port 80, but an empty character.
Returned value in this example :""
5, window. location. pathname
URL path (that is, the file address)
Returned value in this example:/fisker/post/0703/window.location.html
6. window. location. search
Query (parameter)
In addition to assigning values to dynamic languages, we can also assign values to static pages and use javascript to obtain expected parameter values.
Return Value in this example :? Ver = 1.0 & id = 6
7. window. location. hash
Anchor
Returned value in this example: # imhere

Related Article

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.