Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / August 2007



Tip: Looking for answers? Try searching our database.

IE 7, getElementById, iframe

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
datvong@gmail.com - 30 Aug 2007 20:06 GMT
On Internet Explorer 7, getElementById does not work if I have an
iframe in my html.

<html>
<script language="Javascript">
function Init()
{
   var win = document.getElementById("0");
   alert(win);
}
</script>

<body onLoad="Init();">
  <iframe />
  <div id="0"> Hello World</div>
</body>
</html>

In this case, win is NULL.  However, if I move the iframe BELOW the
div, then it works fine. Weird.
Randy Webb - 30 Aug 2007 20:31 GMT
datvong@gmail.com said the following on 8/30/2007 3:06 PM:
> On Internet Explorer 7, getElementById does not work if I have an
> iframe in my html.

Don't blame IE7 for your own mistakes. FF gives the same results - as it
should.

> <html>
> <script language="Javascript">
[quoted text clipped - 13 lines]
> In this case, win is NULL.  However, if I move the iframe BELOW the
> div, then it works fine. Weird.

Try validating your HTML. <iframe /> isn't valid HTML. Change your
iframe to proper markup: <iframe></iframe> and IE7 will give you the
results you expect as will any other browser. It will also allow your
text to show up on the page.

The first indication that there was a problem with your HTML should have
been that the text "Hello World" doesn't show up on the page.

Second, ID attributes are not allowed to start with a number.

Signature

Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.