Several Methods to refresh the current page

Source: Internet
Author: User
Tags server memory

Reload method, which forces the browser to refresh the current page.
Syntax: location. Reload ([bforceget]) parameter: bforceget; 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 method. This method replaces the items currently cached in the History (client) by specifying the URL. Therefore, after using the replace method, 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 like this: location. Replace (location. href );

 

Return to and refresh the page:

Location. Replace (document. referrer );

Document. referrer // the URL of the previous page

Do not use history. Go (-1) or history. Back (); to return and refresh the page. These two methods do not refresh the page.

Appendix:
How to refresh the page with javascript:
1 history. Go (0)
2 location. Reload ()
3 location = Location
4 location. Assign (location)
5 document.exe ccommand ('refresh ')
6 window. navigate (location)
7 location. Replace (location)
8 Document. url = location. href

 

How to automatically refresh the page:
1. Automatically refresh the page: Add the following code to the <Meta http-equiv = "refresh" content = "20">
20 indicates refreshing the page every 20 seconds.

2. automatic page Jump: Add the following code to the <Meta http-equiv = "refresh" content = "20; url = http://www.wyxg.com">
20 means jump to the http://www.wyxg.com page every 20 seconds

3. Automatically refresh JS version on the page
<Script language = "JavaScript">
Function myrefresh ()
{
Window. Location. Reload ();
}
SetTimeout ('myrefresh () ', 1000); // refresh once per second
</SCRIPT>

 

JS refresh framework script statement

// How to refresh the page containing the framework
<Script language = JavaScript>
Parent. Location. Reload ();
</SCRIPT>

// Refresh the parent window in the Child Window
<Script language = JavaScript>
Self. opener. Location. Reload ();
</SCRIPT>
(Or <a href = "javascript: opener. Location. Reload ()"> refresh </a>)

// How to refresh the page of another framework
<Script language = JavaScript>
Parent. Another frameid. Location. Reload ();
</SCRIPT>

If you want to refresh the window when closing the window or refresh the window when opening the window, you can call the following statement in <body>.

<Body onload = "opener. Location. Reload ()"> refresh when opening a window
<Body onUnload = "opener. Location. Reload ()"> refresh when disabled

<Script language = "JavaScript">
Zookeeper opener.doc ument. Location. Reload ()
</SCRIPT>

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.