Monday, October 31, 2011

Invoking Controls and function in page and iframes in javascript

How to access child window from parent window?

We can access the child window elements by using the window handle that will be returned by the window.open() method, as shown below:
winobj=window.open(..)
...
winobj.document.getElementById("elementname").value=""

The winobj is actually a window object instance of the newly created window


How to access parent window from child window ?
window.opener.document.getElementById('text1').value="Value changed.." ;
window.opener.location.reload

How to call parent page from iframe?

Window.parent.functionName();
window.parent.document.getElementId(...);

var winobj=window.open(..); // this is for opening new child window
winobj.document.getElementById("elementname").value="";

How to call iframe function from parent page?
Assume your iFrame's id is "targetFrame" and the function you want to call is targetFunction():
document.getElementById('targetFrame').contentWindow.targetFunction();
You can also access the frame using window.frames instead of document.getElementById.

or

window.frames.iframeName.functionName();


How to call parent page from user control?

To access function inside parent page

Window.parent.functionName();
To access controls inside parent page

window.parent.document.getElementId(...);

No comments:

Post a Comment