JS page to refresh the current page of some research

Source: Internet
Author: User
Tags call back php code

Did not hesitate to use the following JS code

The code is as follows Copy Code

Parent.window.location.reload ();

Explain why to parent, because the interactive operation is in the page submission form to the page a hidden iframe, interactive completion after the need to refresh the current page, so with parent, call back to the current page to refresh.

There is no logical problem, and it does use it to achieve a page refresh.

Then accidentally, with FF to perform the above operation (the previous development has been to use Chrome, my main browser is also chrome), the following scene appears

But there's no such thing as Chrome. This kind of prompt, usually because has post the data page of the past refresh will appear, but I refresh the current page, why there are data post, let me quite depressed.

Later Baidu a bit, found Window.location.reload () This method by a lot of people criticized, because when Window.location.reload () refresh the current page, the page inside the IFrame will also refresh, And FF is will record an IFRAME once opened the page, so I refresh the current page, the equivalent of I just submitted to the IFRAME of the processing page in the IFRAME inside again, so appear above the situation.

Alas, it seems to be a browser-compatible hack, I really do not know that the FF strong or defective good ... Record an IFRAME page why!

Here is a demo to test FF under the Window.location.reload () refresh the current page will let the IFRAME also refreshed.

When you point to resend each time, FF will continue to alert and constantly pop-up this prompt, can be said to be dead loop ...

So there is no way, can only find ways to solve Bai, online solutions are

The code is as follows Copy Code
Parent.window.location.href = Parent.window.location.href;

But if the current page has anchor point, this method does not work (because the URL has anchor point, is not refreshed, do not understand the words of their own literacy bar)

So I improved the above method and wrote

Here is the PHP code:

The code is as follows Copy Code

echo "<script>parent.window.location.href = ' {$_server[' http_referer ']} ';</script>";

Treat Referer as a refreshed URL. Because it is submitted to the processing page to hide the IFRAME, so referer must be the current page will not be wrong, take referer, because do not take the anchor point, so the refresh function is not a problem.

Several ways to refresh a page:

The code is as follows Copy Code

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

Ways to automatically refresh pages:
1. Page Automatic refresh: Add the following code to the <meta http-equiv= "Refresh" content= ">"
20 of which means that the page is refreshed every 20 seconds.

2. Page Automatic Jump: Add the following code to the <meta http-equiv= "Refresh" content= "20;url=http://www.wyxg.com" >
20 of which refers to 20 seconds after the jump to the http://www.wyxg.com/page

3. Page automatically refresh JS version
<script language= "JavaScript" >
function Myrefresh ()
Window.location.reload ();
SetTimeout (' Myrefresh () ', 1000); Specify 1 seconds to refresh once

Asp. NET how to output refresh the parent window script statement
1. This.response.write ("<script>opener.location.reload ();</script>");

2. This.response.write ("<script>opener.window.location.href = opener.window.location.href;</script>") ;

3. Response.Write ("<script language=javascript>opener.window.navigate (" You want to refresh the page. asp ');</script> ")

JS Refresh Frame Script statement

How to refresh the page that contains the frame with
<script language=javascript>
Parent.location.reload ();

child window refreshes parent window
<script language=javascript>
Self.opener.location.reload ();
(or <a href= "javascript:opener.location.reload ()" > Refresh </a>)
How to refresh another frame's page with
<script language=javascript>
Parent.otherFrameID.location.reload ();

If you want to close the window or refresh when you want to open windows, call the following statement in <body>.
<body onload= "Opener.location.reload ()" > Refresh when opening windows
<body onunload= "Opener.location.reload ()" > Refresh when closed
<script language= "JavaScript" >
Window.opener.document.location.reload ()

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.