Reputation: 1669
I am calling the parent function like window.parent.functionname();
from the child page. How can i call the window.child.function()
from the parent page to child page.
Any help is appreciated.
Upvotes: 10
Views: 29856
Reputation: 1697
var win = null;
function openAndCall(id){
if (win!=null && win.closed==false){
win.close();
}
win = window.open("/somePage");
win.onload = function(){
win.callSome(id);
};
}
Upvotes: 3
Reputation: 73916
Parent page
var windowRef = null;
function openChildWindow() {
if ((windowRef != null) && (windowRef.closed == false)) {
if (windowRef.closed == false) windowRef.close();
windowRef = null;
}
var windowUrl = 'ChildPage.aspx';
var windowId = 'NewWindow_' + new Date().getTime();
var windowFeatures = 'channelmode=no,directories=no,fullscreen=no,' + 'location=no,dependent=yes,menubar=no,resizable=no,scrollbars=yes,' + 'status=no,toolbar=no,titlebar=no,' + 'left=0,top=0,width=400px,height=200px';
windowRef = window.open(windowUrl, windowId, windowFeatures);
windowRef.focus();
// Need to call on a delay to allow
// the child window to fully load...
window.setTimeout(callChildWindowFunction(), 1000);
}
function callChildWindowFunction() {
if ((windowRef != null) && (windowRef.closed == false)) windowRef.childWindowFunction();
}
Child Page
function childWindowFunction() {
alert('Hello from childWindowFunction()');
}
Upvotes: 3
Reputation: 5822
Give your iFrame an id and try
document.getElementById("iFrameId").contentWindow.functionname()
This works even when you have multiple iFrames in the same page irrespective of their order.
Upvotes: 11
Reputation: 8728
Do you have an iframe?
Do something like that:
window.frames[0].contentDocument.functionname();
Upvotes: 4