If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Practice Script - Iframe Interaction

When you assign an element of a window to a variable with getElementById() or getElementByName(), that variable is referring to an Element Object that is a property of the Window Object. This behavior is not true for frames, however; the value of the name or ID of a frame element refer to a Window Object as opposed to an Element Object.

This means that you can treat that frame in your code as if it were its own Window Object using the Name or ID that you have assigned to that frame. I provide an example below.

HTML
The id "fone" given to this <iframe> Element does not refer to an Element Object, it refers to a Window Object.

What is the browser restriction for this? It does not work for Firefox 12 at all!

Code:

fone is undefined

And with document.getElementById('fone').document I also get an exception

Code:

document.getElementById('fone').document is undefined

Usually you'll have to use .contentWindow or .contentDocument to get the respective window or document object from inside the iframe!

Can you post the entire code so we can have a look see. I've only tested in FF 8.

Also the error "document is undefined". Isn't that pretty much impossible. Document is always defined right? If document is undefined then there is no way to define a variable to any of that documents properties. Which pretty much renders client-side scripting useless.