Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload Main Page from within an iFrame

Tags:

javascript

Within my scenario, I have a button within an iframe section of my page that performs some database processing.

What I need is a means of performing a page refresh of the main page, when this button within the iframe is pressed.

I am seeking some JavaScript code that I can trigger within the iframe, that will reload the main window holding the iframe.

like image 589
tonyf Avatar asked Jun 05 '09 06:06

tonyf


People also ask

How do you refresh an iframe page?

window. location. reload(true); With firefox this works fine, it only refreshes the current page within the iframe.

How do I use an iframe to find a specific part of a Web page?

Set the iframe to the appropriate width and height and set the scrolling attribute to "no". If the area you want is not in the top-left portion of the page, you can scroll the content to the appropriate area.

What is location reload ()?

The location. reload() method reloads the current URL, like the Refresh button.


5 Answers

window.top.location.reload();
like image 56
Matthew Flaschen Avatar answered Oct 16 '22 16:10

Matthew Flaschen


If the parent's and child iframe domains will be different you will get cross-window security error, in that case you can try to use following:

window.parent.location = document.referrer;
like image 26
Sid Avatar answered Oct 16 '22 17:10

Sid


window.parent.location.reload();
like image 32
Jeff Walden Avatar answered Oct 16 '22 16:10

Jeff Walden


We can easily achieve the facing goal by set target="_parent" to the Links which inside the iframe.

Just like the following demo shows:

<!--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>
like image 39
Prabhu Nandan Kumar Avatar answered Oct 16 '22 18:10

Prabhu Nandan Kumar


define allFrame variable on your top frame:

var allFrame=1

and on all your frames check this function

if(top.allFrame === undefined)
{
    window.parent.location = "your website top frame";
}
like image 29
Anar Quliyev Avatar answered Oct 16 '22 18:10

Anar Quliyev