There are N types of page refresh code in js. Next I will introduce you to the code of the page refresh in js, including: Click to refresh the page, regularly refresh pages and other implementation methods. For more information, see.
Let's briefly introduce some page refresh statements.
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 found
Automatically refresh js edition on the timed page
Program code
The Code is as follows: |
Copy code |
<Meta http-equiv = "refresh" content = "20"> |
Or write it like this
The Code is as follows: |
Copy code |
<Script language = "Javascript"> Function myrefresh () { Window. location. reload (); } SetTimeout ('myrefresh () ', 1000); // refresh once per second </Script> |
Window. location. Reload () and window. location. href = window. location. href;
The Code is as follows: |
Copy code |
<A onclick = "javascript: window. location. href = window. location. href;">
<A onclick = "javascript: window. location. reload ();"> |
The test results are the same. The form is not submitted.
The Code is as follows: |
Copy code |
<Input type = "submit" onclick = "javascript: window. location. reload ();" value = "click" id = "btnVCode"/> <Input type = "submit" onclick = "javascript: window. location. href = window. location. href;" value = "click" id = "btnVCode"/> |
Submit data
Window. location. Reload () should be refreshed. (If data is submitted, the system will prompt whether to submit (yes and no ))
Window. location. href = window. location. href;
It is recommended that you do not use location. reload (), but use location = location, and use showModalDialog and showModelessDialog in the mode window.
Js refresh window: window. location. replace (window. location. href)
The Code is as follows: |
Copy code |
Window. location. reload ();
Window. history. go (0 ); Window. location. assign (window. location. href) |
Differences between window. location. href and window. location. replace:
1. html-> 2.html-> 3.html
After the system starts from 1.html to 2.html, there are two buttons in 2. btn1is named w.location.href1_3.html, btn2is named window.location.replace(3.html), then,
When you click btn2to enter 3rd, use unzip history.go(-1##wondo=history.back(); to return 2.html
Experience and differences between window. location. href and window. location. replace
When window. location. href is used, window. history. go (-1) or window. history. back () is used.
When window. location. replace ('url') is used, window. history. go (-1) or window. history. back () is not used.
Window. location. replace ("3.jsp"); is a jump that does not send a request to the server.
Window. history. go (-1); window. history. back (); the method is to decide which page to jump to based on the request recorded by the server.
Window. location. href ("3.jsp"); is the redirect request sent to the server, window. history. go (-1); wondow. history. the back () method determines the page to jump to based on the request recorded by the server
JS refresh framework script statement:
The Code is as follows: |
Copy code |
// How to refresh the page containing the framework <Script language = JavaScript> Parent. location. reload (); </Script> // Refresh the parent window in the Child Window <Script language = JavaScript> Self. opener. location. reload (); </Script> (Or <a href = "javascript: opener. location. reload ()"> refresh </a>) // How to refresh the page of another framework <Script language = JavaScript> Parent. Another FrameID. location. reload (); </Script> |
If you want to refresh the window when closing the window or refresh the window when opening the window, you can call the following statement in <body>:
The Code is as follows: |
Copy code |
<Body onload = "opener. location. reload ()"> refresh when opening a window <Body onUnload = "opener. location. reload ()"> refresh when disabled <Script language = "javascript"> Zookeeper opener.doc ument. location. reload () </Script> |
Refresh the page of another framework
Statement 1. window. parent. frames [1]. location. reload ();
Statement 2. window. parent. frames. bottom. location. reload ();
Statement 3. window. parent. frames ["bottom"]. location. reload ();
Statement 4. window. parent. frames. item (1). location. reload ();
Statement 5. window. parent. frames. item ('bottom '). location. reload ();
Statement 6. window. parent. bottom. location. reload ();
Statement 7. window. parent ['bottom ']. location. reload ();