How to reload Main Page from within an iFrame

Javascript

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

window.top.location.reload();

Solution 2 - Javascript

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;

Solution 3 - Javascript

window.parent.location.reload();

Solution 4 - Javascript

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>

Solution 5 - Javascript

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";
}

Solution 6 - Javascript

window.opener.top.location.reload();

Solution 7 - Javascript

If you code Page with aspx C# you can view code:

ClientScript.RegisterStartupScript(this.GetType(), "LoadParent", "<script language=javascript>window.parent.location.reload();</script>");

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontonyfView Question on Stackoverflow
Solution 1 - JavascriptMatthew FlaschenView Answer on Stackoverflow
Solution 2 - JavascriptSidView Answer on Stackoverflow
Solution 3 - JavascriptJeff WaldenView Answer on Stackoverflow
Solution 4 - JavascriptPrabhu Nandan KumarView Answer on Stackoverflow
Solution 5 - JavascriptAnar QuliyevView Answer on Stackoverflow
Solution 6 - JavascriptSerdariView Answer on Stackoverflow
Solution 7 - Javascriptdac san vinafoodView Answer on Stackoverflow