Referencing elements within an iframe in Firefox.

R

Razzbar

I've written several utility pages that use a dynamically created
iframe. The iframe typically has a form that is populated by the main
page. Then the form is submitted to be processed, and the returning
page does something -- call a function on the main page, change a
variable on the main page, etc.

All this stuff I created works on IE. Sorry, didn't have other browsers
available to test. Now I have access to a machine with FF, and none of
these scripts work.

So, short and sweet: What is the proper way to reference a form on an
iframe from the parent doc in firefox? Also, call a function from the
parent to the iframe, and vice-versa, call a function on the parent doc
from the iframe when it loads?

TIA...
 
P

Paul J. Le Genial

Did you check the error messages in the Tools/JavascriptConsole ?
Have a look also in the Tools/DOM inspector.
 
R

RobB

Razzbar said:
I've written several utility pages that use a dynamically created
iframe. The iframe typically has a form that is populated by the main
page. Then the form is submitted to be processed, and the returning
page does something -- call a function on the main page, change a
variable on the main page, etc.

All this stuff I created works on IE. Sorry, didn't have other browsers
available to test. Now I have access to a machine with FF, and none of
these scripts work.

So, short and sweet: What is the proper way to reference a form on an
iframe from the parent doc in firefox? Also, call a function from the
parent to the iframe, and vice-versa, call a function on the parent doc
from the iframe when it loads?

TIA...

Should be something here...

http://www.faqts.com/knowledge_base/index.phtml/fid/127
 
R

Razzbar

Paul said:
Did you check the error messages in the Tools/JavascriptConsole ?
Have a look also in the Tools/DOM inspector.

Yes, but the information wasn't useful. It's a compatibility issue,
with IE being non-DOM compliant in the way you refer to an iframe.

I found the DOM way to address the iframe here,
http://www.codingforums.com/showthread.php?t=45000

Basically, the DOM way to refer to an iframe element from the parent
doc is
document.getElementById('iframeId').contentDocument.getElementById('elementID')

While the IE way is
document.frames['frameName'].elementName
 
R

Razzbar

Should be. Seperating the wheat from the chaff is the problem. Most of
those examples are not crossbrowser solutions. There doesn't seem to be
one way that works with IE
and the DOM.
 
R

RobB

Razzbar said:
Should be. Seperating the wheat from the chaff is the problem. Most of
those examples are not crossbrowser solutions. There doesn't seem to be
one way that works with IE
and the DOM.

iframes are unusual in that they are represented in the DOM by *two*
host objects, an HTMLElement object & a window (frame) type object.
Which one you access depends, naturally, on what you need to do with
it. To allow cross-referencing, the special properties 'contentWindow'
and 'contentDocument' were created.

http://mips.ath.cx/js-iframe-content.html
 
C

Csaba2000

Razzbar said:
I found the DOM way to address the iframe here,
http://www.codingforums.com/showthread.php?t=45000

Basically, the DOM way to refer to an iframe element from the parent doc is
document.getElementById('iframeId').contentDocument.getElementById('elementID')

For the frames method, you can get to the iframe's doc (cross browser) with:
window.frames[frameIdentifier].document...

IE can also do (note capitalization):
document.getElementById('iframeId').Document.getElementById('elementID')
document.getElementById('iframeId').Document.all['elementID']


Csaba Gabor from Vienna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top