Home >Web Front-end >HTML Tutorial >Introduction to usage examples of a link refresh page and js refresh page_HTML/Xhtml_Web page production

Introduction to usage examples of a link refresh page and js refresh page_HTML/Xhtml_Web page production

WBOY
WBOYOriginal
2016-05-16 16:38:491137browse

1. How to use a link:

Copy code
The code is as follows:

< ;a href="javascript:history.go(-1);">Return to the previous page
Refresh the current page

The effect of #top didn’t work for me. I directly wrote refresh the current page but it did.

2. How to refresh the current page in 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 the GET method to fetch the latest page from the server, which is equivalent to the client clicking F5 ("Refresh")

replace method, which replaces the current cache in the history by specifying the URL (client) project, so 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 pressing 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);

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

How to automatically refresh the page:
1. Automatically refresh the page: Add the following code to the area

20 of them means refreshing the page every 20 seconds.

2. The page automatically jumps: add the following code to the area

The 20 fingers will jump to the http://www.wyxg.com page after 20 seconds

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); // Specify a refresh time of 1 second


JS refresh frame script statement

Copy code
The code is as follows:

//How to refresh the page containing the frame using

//The child window refreshes the parent window

(OrRefresh )
//How to refresh the page of another frame using


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

Copy code
The code is as follows:

Refresh when opening the window
Refresh when closing

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