javascript: window.document returns null -


i have html document named 'welcome.html' uses iframe referring 'main.html'. inside 'inner.html' file iframe used referring 'inner.html'. inside 'inner.html' want access elements of / or communicate between elements of main.html. used following way in javascript,

method 1:

.. .. var top_window = window.top; alert(top_window)    // gives top window object var main_window = top_window.frames['main-frame'] // assuming 'main-frame' name given @ iframe declaration 'main.html' alert(main_window)    // gives main window object var main_document = main_window.document alert(main_document)    // gives 'undefined' .. .. 

method 2:

.. .. var parent_window = window.parent; alert(parent_window)    // gives parent window object, is, 'main.html' window object var parent_document = parent_window.document alert(parent_document)    // gives 'null' .. .. 

i want document object of 'main.html's window object. both methods don't work out. there sound solution or doing in wrong manner?

thanks in advance.

the easiest way communicate between iframe s getting window objects. create getter setter function in both parent , child , pass values between 2 window objects.

this return window object of iframe

var contentwindow = document.getelementbyid('iframe').contentwindow  

from iframe access parent window using window.parent


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -