1. How to use the link: Copy code The code is as follows:<a href="javascript:history.go(-1);">Return to the previous page</a> <a href="#top">Refresh current page</a> The #top effect didn't work for me, but it worked when I directly wrote <a href="">Refresh current page</a>. 2. How to refresh the current page with JS The reload method forces the browser to refresh the current page. Syntax: location.reload([bForceGet]) Parameter: bForceGet, optional parameter, default is false, get the current page from the client cache. true, then the latest page is retrieved from the server using GET, which is equivalent to the client clicking F5 ("refresh") The replace method replaces the item currently cached in the history (client) by the specified URL. Therefore, after using the replace method, you cannot access the replaced URL by "forward" and "backward". 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, when the page method="post", a "page expired" prompt will appear. That's because of the Session security protection mechanism. It can be imagined that: when the location.reload() method is called, the aspx page already exists in the server's memory, so it must be IsPostback. If there is such an application: We need to reload the page, that is, we expect the page to be recreated on the server, and we expect it to be Not IsPostback. Here, location.replace() can accomplish this task. The replaced page is regenerated on the server each time. You can write: location.replace(location.href); Go back and refresh the page: Copy code The code is as follows:location.replace(document.referrer); document.referrer //URL of the previous page Do not 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 with 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 How to automatically refresh the page: 1. Automatic page refresh: Add the following code to the <head> area <meta http-equiv="refresh" content="20"> 20 means refreshing the page every 20 seconds. 2. Automatic page jump: Add the following code to the <head> area <meta http-equiv="refresh" content="20;url=http://www.wyxg.com"> 20 means jumping to http://www.wyxg.com after 20 seconds. 3. Page automatic refresh js version Copy code The code is as follows:<script language="JavaScript"> function myrefresh() { window.location.reload(); } setTimeout('myrefresh()',1000); //Specify refresh once every 1 second </script> JS refresh frame script statement Copy code The code is as follows://How to refresh the page containing the frame <script language=JavaScript> parent.location.reload(); </script> //The child window refreshes the parent 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 frame <script language=JavaScript> parent.anotherFrameID.location.reload(); </script> If you want to refresh when closing the window or when opening the window, just call the following statement in <body>. Copy code The code is as follows:<body onload="opener.location.reload()"> Refresh when opening the window <body onUnload="opener.location.reload()"> Refresh on close <script language="javascript"> window.opener.document.location.reload() </script> |
<<: Problems and solutions for deploying Nginx+KeepAlived cluster dual-active architecture in VMware
>>: 30 excellent examples of color matching in web design
What is JSX JSX is a syntax extension of Javascri...
Data sorting asc, desc 1. Single field sorting or...
This article mainly introduces the detailed proce...
Suppose now you want to add an item like this to ...
Docker Overview Docker is an open source software...
Preface I believe many students are already famil...
Purpose: Under Linux, the server program may be d...
1. Dynamic parameters Starting from 2.6.0, you ca...
This is the effect to be achieved: You can see th...
Add the jvm.options file to the elasticsearch con...
1. Use the following command to set the ssh passw...
Use the vscode editor to create a vue template, s...
Preface Generator functions have been in JavaScri...
Overview When a 500 or 502 error occurs during ac...
<body> <div id="root"> <...