Web page Refresh Page Method summary

Source: Internet
Author: User

1. Automatic page refresh: Add the following code to the
<meta http-equiv= "Refresh" content= ">"

20 refers to a refresh of the page every 20 seconds.

2. Page Auto-jump: Add the following code to the
<meta http-equiv= "Refresh" content= "20;url=https://www.baidu.com/" >

20 means 20 seconds after the jump to https://www.baidu.com/Baidu home page.

3. Page automatically refresh JS version
(1) Reload method, which forces the browser to refresh the current page.
Syntax: Location.reload ([Bforceget])
Parameters: Bforceget, optional parameter, default is False, the current page is taken from the client cache.
True, the latest page from the server is taken as a GET, which is equivalent to the client clicking F5 ("Refresh").
<script language= "JavaScript" >  function myrefresh () {    window.location.reload ();  }  SetTimeout (' Myrefresh () ', 1000); Specify a 1-second refresh once </script>

(2) The Replace method, which replaces the currently cached item in the history by specifying a URL, so you cannot access the URL that has been replaced by forward and back after using the Replace method.
syntax: Location.replace (URL)
usually used: location.reload () or history.go (0) to do.
This method is similar to the client Point F5 Refresh page, because the session security mechanism, page method= "Post", will appear "page expiration" prompt.
when the Location.reload () method is called, the ASPX page is already present in the server's memory, so it must be IsPostback.
If there is such an application: the page needs to be reloaded, that is, the desired page can be re-created on the server and the expectation is not IsPostback.
here Location.replace () can complete this task. The Replace page is regenerated on the server each time.
Code: Location.replace (location.href);
To return and refresh the page:

Location.replace (document.referrer);d ocument.referrer   //URL of previous page
4.JavaScript Script statement to refresh the framework
  Refresh the page that contains the frame with   <script language= "JavaScript" >    parent.location.reload ();</script>  // child window Refreshes parent window <script language= "JavaScript" >    self.opener.location.reload ();</script>  //(or < A href= "javascript:opener.location.reload ()" > Refresh </a>)  //Refresh the page of another frame with <script language= "JavaScript" >    parent. Another FrameID.location.reload ();</script>  
5. Implement JSP page refresh automatically
Response.addintheader ("Refresh", ten);  Refreshes the Response.sendredirect ("index.jsp") every 10 seconds;  Make page Jump Response.AddHeader ("Refresh", "3;url=http://www.baidu.com");  Automatically jump to Baidu after 3 seconds

the above is not very clear, I would add:
response has the following four ways to implement the JSP page automatically refresh, respectively:
AddHeader (String ame,string value);
Addintheader (String name, int value);
SetHeader (String name,string value);
Setintheader (String name,int value);
Note that the arguments are passed.
additionally AddHeader (string name,string value) and SetHeader (string name,string value).
You can also implement the ability to jump to a specified page after a specified number of seconds, for example:
Response.AddHeader ("Refresh", "3;url=http://www.baidu.com"); 3 seconds to skip to Baidu homepage
Response.setheader ("Refresh", "5;url=http://www.baidu.com"); 5 Seconds to skip to Baidu homepage

6. Call the following statement in <body> if you want to refresh when you close the window or if you want to open the window
<body onload= "Opener.location.reload ()" >  < refresh--><body onunload=!--open Window  " Opener.location.reload () ">  < Refresh--><script language=" javascript "when the window is closed!-->   Window.opener.document.location.reload () </script>

do not use History.go (-1), or history.back (), to go back and refresh the page, neither of these methods refreshes the page.

Summary of JavaScript Refresh page methods:

①history.go (0)
②location.reload ()
③location=location
④location.assign (location)
⑤document.execcommand (' Refresh ')
⑥window.navigate (location)
⑧location.replace (location)
⑨document. Url=location.href

Web page Refresh Page Method summary

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.