Forum Moderators: open

Message Too Old, No Replies

can't access an iframe

         

mizas

2:59 pm on May 31, 2006 (gmt 0)



I have been trying to access and element on form inside an iframe and just can't seem to get it to work. I always get an error that says the form has no properties. There are multiple forms in the iframe so the forms are being accessed in an array. I want to access the first element of the first form and have been trying:

window.frames['<frame_name/frame_id>'].document.forms[0].elements[0]

mcvoid

8:25 pm on May 31, 2006 (gmt 0)

10+ Year Member



I can't speak authoritatively on this, but since an iframe is inside a document already and not a frame in a frameset, wouldn't it be accessed as such?

//get iframe object
fobject = document.getElementById('frame_name');

then this will be your reference:
fobject.document.forms[0].elements[0]

That's probably the easiest way since there's an element inside your document that has it's own document object and its own viewport and everything. This applies to other stuff as well - styles won't carry over to an iframe - that document inside has to get it's own styles.

texmex

9:25 pm on Jun 1, 2006 (gmt 0)

10+ Year Member



You cannot access the document object (or any of it's elements) within a frame, if the src of that frame comes from a diferent website, to that of the script attempting to get access.

It's a standard security measure that ALL browsers should follow.

If the src of the frame is from the same site as the document containing your javascript, it shouldn't be a problem.