SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript IFrame Height Change Not Working if FF

    The script below works perfect at changing the height of an iframe depending on a dynamic factor.

    Code:
    <script language="javascript">
    if (document.all) 
    {
    window.document.all.slideshow.style.height = 88;
    }
    else 
    {
    i = window.document.getElementById("slideshow");
    i.style.height = 88;
    }
    </script>
    What am I missing? It works perfect in IE though.

    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well first off, document.all is pretty much unnecessary now-a-days with the modern browsers, unless you are trying to make sure that IE 4 recognizes your script (and I think Iframes fail in IE4 anyway) so you are probably fine to scrap the use of the conditional.

    2nd, when using Javascript to set style attributes, you have to treat the attributes as strings, even if they are numbers. So hence:

    Code:
    i.style.height = "88px";
    Note that I include the units inside the quotes.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by casbboy View Post
    The script below works perfect at changing the height of an iframe depending on a dynamic factor.

    Code:
    <script language="javascript">
    if (document.all) 
    {
    window.document.all.slideshow.style.height = 88;
    }
    else 
    {
    i = window.document.getElementById("slideshow");
    i.style.height = 88;
    }
    </script>
    What am I missing? It works perfect in IE though.
    Code:
    i = window.document.getElementById("slideshow");
    i.height = 88;
    i.width=600;

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    using the px and the quotes got it working.

    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by casbboy View Post
    using the px and the quotes got it working.
    Just as long as you appreciate that using the style property is dependent upon CSS support being present.

  6. #6
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you using document.all? IE5+ support document.getElementById().

    What happens if an Netscape 4 user tries to use that?

    My suggestion is that if you want to support IE4, you can use the following and just test for document.getElementById() support.

    Code:
    if(document.all && !document.getElementById) { //IE4 support
      document.getElementById = function(id) { return document.all[id]; }
    }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •