Common JavaScript code refresh current page

Source: Internet
Author: User

Use location. reload () or location. href to refresh the current page in js. Of course, we can use window. parent. frames to refresh the framework page. Let's take a look.

Reload MethodThis method forces the browser to refresh the current page.

Syntax: location. reload ([bForceGet]) parameter: bForceGet; optional parameter. The default value is false. The current page is retrieved from the client cache. True, the GET method is used to obtain the latest page from the server, which is equivalent to clicking F5 ("refresh") on the client ")

Example

The Code is as follows: Copy code

<Input type = button value = "Refresh 1" onclick = "window. parent. frames [1]. location. reload ()">
<Input type = button value = "Refresh 2" onclick = "window. parent. frames. bottom. location. reload ()">
<Input type = button value = "Refresh 3" onclick = "window. parent. frames ['bottom ']. location. reload ()">
<Input type = button value = "Refresh 4" onclick = "window. parent. frames. item (1). location. reload ()">
<Input type = button value = "Refresh 5" onclick = "window. parent. frames. item ('bottom '). location. reload ()">
<Input type = button value = "Refresh 6" onclick = "window. parent. bottom. location. reload ()">
<Input type = button value = "Refresh 7" onclick = "window. parent ['bottom ']. location. reload ()">

1. windowless refers to the front page. For example, this refers to the top.html page.
2. parent refers to the parent page of the current page, that is, the framework page containing it. In this example, framedemo.html is used.
3. frames is a window object and an array. Represents all the child pages in the framework.
4. item is a method. Returns the elements in the array.
5. If the sub-page is also a framework page and contains other sub-pages, some of the above methods may not work.

Appendix:

How to refresh the page with Javascript:

1 history. go (0)
2 location. reload ()
3 location = location
4 location. assign (location)
5 document.exe cCommand ('refresh ')
6 window. navigate (location)
7 location. replace (location)
8 document. URL = location. href

Example

The Code is as follows: Copy code

<Jscript>
 
Function refreshopage ()
{
Window. location. reload ();
}
</Jscript>

1. Automatically refresh the page: Add the following code to the

The Code is as follows: Copy code

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

20 indicates refreshing the page every 20 seconds.

2. automatic page Jump: Add the following code to the

The Code is as follows: Copy code

<Meta http-equiv = "refresh" content = "20; url = http://www.bKjia. c0m">

20 means jump to the http://www.bKjia. c0m page every 20 seconds

3. Automatically refresh js version on the page

The Code is as follows: Copy code

<Script language = "JavaScript">
Function myrefresh ()
{
Window. location. reload ();
}
SetTimeout ('myrefresh () ', 1000); // refresh once per second
</Script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.