JS method to refresh the current page: 1. Reload method, this method forces the browser to refresh the current page, the syntax is "location.reload([bForceGet])"; 2. Replace method, this method specifies the URL Replace the item currently cached in the history (client), so after using the replace method, the replaced URL cannot be accessed through "forward" and "back", the syntax is "location.replace(URL)".
js Refresh the current page?
reload method, this method forces the browser to refresh the current page.
Syntax: location.reload([bForceGet]). Parameters: bForceGet, optional parameters, default is false, retrieve the current page from the client cache. If true, the latest page will be fetched from the server in GET mode, which is equivalent to the client clicking F5 ("Refresh").
replace Method, this method 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) Come and 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. One 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 recreated on the server side, and we expect Not IsPostback. Here, location.replace() This task can be completed. 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 //The 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.
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
Method to automatically refresh the page:
1. Automatically refresh the page: Add the following code to the area, of which 20 Refers to refreshing the page every 20 seconds.
2. The page automatically jumps: add the following code to the area, among which 20 refers to jumping to the //www.pconline.com.cn page after 20 seconds.
The above is the detailed content of js refresh current page. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.