Home  >  Article  >  Web Front-end  >  Introduction to the usage of a link refresh page and js refresh page

Introduction to the usage of a link refresh page and js refresh page

小云云
小云云Original
2018-03-02 13:21:512160browse

Refreshing the page usually uses a link and js refresh. As for the difference between the two in use, there will be a detailed introduction in the following article. I hope it can help everyone.

1.a Link usage operation:

  1. <a href="javascript:history.go(-1);">返回上一页</a>   
    <a href="#top">刷新当前页</a>


#top has no effect on me. It works. I directly wrote 8aa2918506a11e8a886e85949f1eb079refresh the current page5db79b134e9f6b82c0b36e0489ee08ed but it works.

2. How to refresh the current page with JS

reload method , this method forces the browser to refresh the current page.
Syntax: location.reload([bForceGet])
Parameters: bForceGet, optional parameter, default is false, retrieve the current page from the client cache. true, then use GET method to fetch the latest page from the server, which is equivalent to the client clicking F5 ("Refresh")
replace method, which replaces the item currently cached in the history (client) by specifying the URL. Therefore, after using the replace method, you cannot access the replaced URL through "forward" and "back".
Syntax: location.replace(URL)
In actual application, when refreshing the page, we usually use: location.reload() or history.go(0) to do it. Because this approach is like the client clicking F5 to refresh the page, so when the page's method="post" is used, a "webpage expired" prompt will appear. That's because of Session's security protection mechanism. You can think 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 reload the page, which means we expect the page to be re-created on the server side, and we expect Not IsPostback. Here, location.replace() can accomplish this task. The replaced page is regenerated on the server every time.
You can write like this: location.replace(location.href);
Return and refresh the page:

  1. location.replace(document.referrer);   
    document.referrer //前一个页面的URL

Don’t use history.go( -1), or history.back(); to return and refresh the page. These two methods will not refresh the page.
Attachment:
Several ways to refresh the page using Javascript:

1 history.go(0)
2 location.reload()
3 location=location
4 location .assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href

Methods to automatically refresh the page:
1. Automatically refresh the page: Add the following code to the 93f0f5c25f18dab9d176bd4f6de5d30e area
cbc445b94b07fca83f8f029a735ab635
20 refers to refreshing the page every 20 seconds.

2. Automatic page jump: add the following code to the 93f0f5c25f18dab9d176bd4f6de5d30e area
2739948182f58dcada23c904cf6d45dd
The 20 finger will jump to the http://www.wyxg.com page after 20 seconds
3. The page automatically refreshes js Version

  1. <script language="JavaScript">   
    function myrefresh()   
    {   
    window.location.reload();   
    }   
    setTimeout(&#39;myrefresh()&#39;,1000); //指定1秒刷新一次   
    </script>

JS refresh frame script statement

  1. //如何刷新包含该框架的页面用   
    <script language=JavaScript>   
    parent.location.reload();   
    </script>   
    //子窗口刷新父窗口   
    <script language=JavaScript>   
    self.opener.location.reload();   
    </script>   
    ( 或 <a href="javascript:opener.location.reload()">刷新</a> )   
    //如何刷新另一个框架的页面用   
    <script language=JavaScript>   
    parent.另一FrameID.location.reload();   
    </script>


If you want If you want to refresh when the window is closed or want to refresh when the window is opened, just call the following statement in 6c04bd5ca3fcae76e30b72ad730ca86d.

  1. <body onload="opener.location.reload()"> 开窗时刷新   
    <body onUnload="opener.location.reload()"> 关闭时刷新   
    <script language="javascript">   
    window.opener.document.location.reload()   
    </script>

Related recommendations:

Explanation on how PHP performs database operations and prevents page timeouts and automatically refreshes the page

Javascript refresh page method and location.reload() usage introduction

Detailed example of refreshing page in Javascript

The above is the detailed content of Introduction to the usage of a link refresh page and js refresh page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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