|
|
Referring iframes in javascript - Javascript
|
Views : 543
|
|
Tagged in : Javascript
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
When we have some frames or iframes inside a page and we want to refer/access an iframe element from the main page or main window , then we can use
contentWindow.document property.
for example if we have a iframe with the id "myframe"
<iframe name="myframe" frameborder=0 id="myframe" width=798 height=290 marginheight=0 marginwidth=0 src="sample.php">
then we can access elements inside iframe using
document.getElementById(iframeId).contentWindow.document // works both in IE and firefox
(or)
document.getElementById(iframeId).contentDocument // works in DOM
(or)
window.frames[iframeName].document // works only if the iframe is already loaded by writing code in HTML
From the iframe , the main page or parent document can be reffered by "parent" property
Eg:
parent.document.getElementById('zz'); // will get the object from the parent window with the id 'zz'
|
|
By Vijay, On - 2009-08-28 |
|
|
|