How to reload the main page from iFrame

In my script, I have a button in the iframe section of my page that does some database processing.

What I mostly need is a tool to refresh the page on the main page when this button inside the iframe is clicked.

I would like javascript, which I can call in an iframe, which will reload the main window containing the iframe.

Thank. Tony.

+46
javascript
Jun 05 '09 at 6:05
source share
6 answers
window.top.location.reload(); 
+97
Jun 05 '09 at 6:08
source share
 window.parent.location.reload(); 
+8
Jun 05 '09 at 6:08
source share

If the parent and child iframes are different, you get a cross-window security error, in which case you can try using the following:

 window.parent.location = document.referrer; 
+7
Apr 08 '14 at 9:53 on
source share

We can easily achieve the goal by setting target = "_ parent" in links that are inside the iframe.

As shown in the following demo:

 <!--ParentPage.htm--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> Parent Page <iframe src="FramePage.htm"></iframe> </body> </html> <!--FramePage.htm--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <a href="http://www.g.cn" target="_parent">hello</a> </body> </html> 
+1
Aug 12
source share

define the allFrame variable in the top frame:

 var allFrame=1 

and on all your frames check this function

 if(top.allFrame === undefined) { window.parent.location = "your website top frame"; } 
0
Feb 06 '17 at 5:42 on
source share
 window.opener.top.location.reload(); 
0
Aug 10 '17 at 8:44 on
source share



All Articles