search
HomeheadlinesThe most complete js code example for refreshing the current page in 2018

//reload 方法,该方法强迫浏览器刷新当前页面。语法:location.reload([bForceGet]) 
//参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前页。
//true, 则以 GET 方式,从服务端取最新的页面, 相当于客户端点击 F5("刷新")
//replace 方法,该方法通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后退”来访问已经被替换的URL。语法: 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:

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

Do not use history.go(-1), or history.back(); to return and refresh the page 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 area

<meta http-equiv="refresh" content="20">

20 means the page will be refreshed every 20 seconds.

2. The page will automatically jump: add the following code to the

area中
<meta http-equiv="refresh" content="20;url=http://www.jb51.net">


The 20th finger will jump to the http://www.php.cn page after 20 seconds

3. The page automatically refreshes the js version

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

JS script statement to refresh the frame

//How to refresh the page containing the frame using

<script language=JavaScript>
 parent.location.reload();
</script>

//The child window refreshes the parent window

<script language=JavaScript>
 self.opener.location.reload();
</script>

( OrRefresh )

//How to refresh another frame The page uses

<script language=JavaScript>
 parent.另一FrameID.location.reload();
</script>

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

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


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.