Summary of several methods for JS to refresh the current page

It can be written like this: location.replace(location.href);

Go back and refresh the page:

location.replace(document.referrer);
document.referrer //URL of previous page

Do not use history.go(-1), or history.back(); to go back and refresh the page, these two methods will not refresh the page.

Attachment:
Several methods for Javascript to refresh the page:
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">
where 20 means to refresh 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.jb51.net">
where 20 refers to 20 seconds later Jump to http://www.jb51.net page

3. The page automatically refreshes the js version

Copy the code The code is as follows:

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

Script statement of JS refresh frame
//How to refresh the page containing the frame with   
<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 with   
<script language=JavaScript>
   parent.another FrameID.location.reload();
</script>

If you want to refresh when the window is closed or when the window is opened, you can call the following statement in <body>.

<body onload="opener.location.reload()"> Refresh when opening window
<body onUnload="opener.location.reload()"> Refresh when closing

<script language="javascript">
window.opener.document.location.reload()
</script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324927372&siteId=291194637