Crossbrowser iframes

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

I want to load content into an iframe with script. None of the
following methods, however, work on all browsers - any suggestions
would be appreciated.

// Assume that there is an element whose name and id are both
// 'theIFrame'.

var myUrl='http://www.yahoo.com'

document.getElementById( 'theIFrame' ).location=myUrl;

document.getElementById( 'theIFrame' ).src=myUrl;

window.document.theIFrame.location=myUrl;

var iframe=document.createElement( 'iframe' );
iframe.src=myUrl;
document.body.appendChild( iframe );
 
K

kaeli

I want to load content into an iframe with script. None of the
following methods, however, work on all browsers - any suggestions
would be appreciated.

Standards support frameElement.src, so I'd go with just using that. Both
Gecko (firefox, moz, NN6+) and MSIE support it.

MSIE:

Gecko:
http://www.mozilla.org/docs/dom/domref/dom_frame_ref13.html

W3C HTML 4.01 specs:
http://www.w3.org/TR/html4/present/frames.html#edef-IFRAME

If other browsers can't handle it, oh well. Very few script-type things work
on every single browser in existence. Actually, if you count the text-only
browsers, none do! :p
(do test for an object before using it so it doesn't KILL the non-standard
browsers)

You asked for suggestions, so that's just one. I'm sure someone will come
along with a big long script that works in 15 browsers. *heh*
AFAIC, I support whatever the W3C has and whatever is needed (if anything) to
make it work in Firefox and MSIE.

--
--
~kaeli~
If that phone was up your a$$, maybe you could drive a
little better!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
M

Martin Honnen

Christopher said:
I want to load content into an iframe with script. None of the
following methods, however, work on all browsers - any suggestions
would be appreciated.

// Assume that there is an element whose name and id are both
// 'theIFrame'.

var myUrl='http://www.yahoo.com'

Make sure the name in the <iframe> tag is set then use
if (window.frames['theIframe']) {
window.frames['theIframe'].location.href = myUrl;
}
That gives you IE 4 and later, Netscape 6 and later, Opera 6 and later
and hopefully other browsers implementing window.frames.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top