Automatic JavaScript refresh

Source: Internet
Author: User

Let's take a look at a simple example: <br/> the following uses three tabs named frame.html?top.html?bottom.html as an example to describe how to do this. <Br/> frame.html consists of two pages (bottom.html) under the top (top.html#). The Code is as follows: <br/> <! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> frame </title> <br/> </pead> <br/> <frameset rows = "50%, 50% "> <br/> <frame name = Top src =" top.html "mce_src =" top.html "> <br/> <frame name = bottom src =" bottom.html "mce_src =" bottom.html "> <br/> </frameset> <br/> </ptml> <br/> set top.html (the preceding page) there are seven buttons to actually refresh bottom.html (that is, the following page), you can use the following seven statements, which can be used to watch Yes. <Br/> Statement 1. window. parent. frames [1]. location. reload (); <br/> Statement 2. window. parent. frames. bottom. location. reload (); <br/> Statement 3. window. parent. frames ["bottom"]. location. reload (); <br/> Statement 4. window. parent. frames. item (1 ). location. reload (); <br/> Statement 5. window. parent. frames. item ('bottom '). location. reload (); <br/> Statement 6. window. parent. bottom. location. reload (); <br/> Statement 7. window. parent ['bottom ']. location. reload (); <Br/> the code for the top.html page is as follows: <br/> <! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> top.html </title> <br/> </pead> <br/> <body> <br/> <input type = button value = "Refresh 1" onclick = "window. parent. frames [1]. location. reload () "> <br/> <input type = button value =" Refresh 2 "onclick =" window. parent. frames. bottom. location. reload () "> <br/> <input type = button value =" Refresh 3 "onclick =" window. parent. FRA MES ['bottom ']. location. reload () "> <br/> <input type = button value =" Refresh 4 "onclick =" window. parent. frames. item (1 ). location. reload () "> <br/> <input type = button value =" Refresh 5 "onclick =" window. parent. frames. item ('bottom '). location. reload () "> <br/> <input type = button value =" Refresh 6 "onclick =" window. parent. bottom. location. reload () "> <br/> <input type = button value =" Refresh 7 "onclick =" window. parent ['botto M']. location. reload () "> <br/> </body> <br/> </ptml> <br/> below is the source code of the bottom.html page, to verify that the page below is refreshed, a dialog box is displayed after loading. <Br/> the code for the bottom.html page is as follows: <br/> <! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> bottom.html </title> <br/> </pead> <br/> <body onload = "alert ('I have been loaded! ') "> <Br/> <p> this is the content in bottom.html. </p> <br/> </body> <br/> </ptml> <br/> explanation: <br/> 1.windowis used as the front page. For example, the top.html page is used for this example. <Br/> 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. <Br/> 3. frames is a window object and an array. Represents all the child pages in the framework. <Br/> 4. item is a method. Returns the elements in the array. <Br/> 5. If the child page is also a frame page and contains other child pages, some of the above methods may not work. <Br/> Appendix: <br/> several methods for refreshing the page using JavaScript: <br/> 1 history. go (0) <br/> 2 location. reload () <br/> 3 location = Location <br/> 4 location. assign (location) <br/> 5 document.exe ccommand ('refresh') <br/> 6 window. navigate (location) <br/> 7 location. replace (location) <br/> 8 document. url = location. href <br/> Method for automatically refreshing the page: <br/> 1. automatic page Refresh: add the following code to the <pead> region <br/> <meta http-equiv = "refresh" content = "20"> <br/> 20 indicates every 20 seconds. Refresh the page once. <br/> 2. automatic page Jump: Add the following code to the <pead> area <br/> <meta http-equiv = "refresh" content = "20; url = http://www.Google.com "> <br/> 20 refers to jump to http://www.google.com/page every 20 seconds <br/> 3. automatically refresh JS version on the page <br/> <MCE: script language = "JavaScript"> <! -- <Br/> function myrefresh () <br/>{< br/> window. location. reload (); <br/>}< br/> setTimeout ('myrefresh () ', 1000 ); // refresh once per second <br/> // --> </MCE: SCRIPT> <br/> Asp. net: How to output the script statement for refreshing the parent window <br/> 1. this. response. write ("<MCE: Script Type =" text/JavaScript "> <! -- <Br/> opener. location. reload (); <br/> // --> </MCE: SCRIPT> "); <br/> 2. this. response. write ("<MCE: Script Type =" text/JavaScript "> <! -- <Br/> opener. window. location. href = opener. window. location. href; <br/> // --> </MCE: SCRIPT> "); <br/> 3. response. write ("<MCE: script language = JavaScript> <! -- <Br/> opener. window. navigate (''the page you want to refresh. ASP ''); <br/> // --> </MCE: SCRIPT> ") <br/> JS refresh framework script statement <br/> // how to refresh the page containing the framework <br/> <MCE: script language = JavaScript> <! -- <Br/> parent. location. reload (); <br/> // --> </MCE: SCRIPT> <br/> // refresh the parent window in the Child Window <br/> <MCE: script Language = JavaScript> <! -- <Br/> self. opener. location. reload (); <br/> // --> </MCE: SCRIPT> <br/> (or <a href = "javascript: opener. location. reload () "mce_href =" javascript: opener. location. reload () "> refresh </a>) <br/> // how to refresh the page of another framework <br/> <MCE: script language = JavaScript> <! -- <Br/> parent. another frameid. location. reload (); <br/> // --> </MCE: SCRIPT> <br/> if you want to refresh the window when closing or when you want to open the window, in <body>, call the following statement. <Br/> <body onload = "opener. location. reload () "> refresh when opening a window <br/> <body onUnload =" opener. location. reload () "> refresh when disabled <br/> <MCE: script language =" JavaScript "> <! -- <Br/> zookeeper opener.doc ument. Location. Reload () <br/> // --> </MCE: SCRIPT>

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.