Reputation: 194
tried the accepted answer of this link used top.window.opener to access the parent.html .no luck . below is my code
parentWindow.html
<p>Click the button to write some text to the source (parent) window.</p>
<button onclick="openWin()">Open "myWindow"</button>
<script>
function test1()
{
alert("test1");
}
function openWin()
{
var myWindow = window.open("childWindow.html");
}
</script>
</body>
</html>
childWindow.html
<HTML>
<HEAD>
<title>Child</title>
<SCRIPT type="text/javascript" LANGUAGE="javascript">
function Initialize()
{
try{
if(top.window.opener != null && !top.window.opener.closed)
{
top.window.opener.test1();
}
}catch(e){ alert(e.description);}
}
</script>
</HEAD>
<BODY onload="Initialize()">
</BODY>
</HTML>
Same code tried on server after following the excerpts from this link. Dint help.
Upvotes: 1
Views: 7815
Reputation: 700322
According to the standards, the second parameter should default to _blank
if it is omitted, but all browsers might not follow that. Specify the target so that you know that it really opens in a new window and doesn't replace the current window:
window.open("childWindow.html", "_blank");
Upvotes: 2
Reputation: 4718
I guess what you would like to do is parent.window.opener
:
if(parent.window.opener != null && ! parent.window.opener)
{
parent.window.opener.test1();
}
Hope this helps.
Upvotes: 0