Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Firefox unable to identify iframe

    I'm using buttons to scroll content in an iframe. Works fine on IE and Chrome.
    Firefox cannot identify the frame and I get this error

    Error: window.frames.iframe is undefined

    My code is
    Code:
    var mypage= eval(window.frames["iframe"].contentlayer.style);
    My iframe is
    Code:
    <iframe id="iframe" src="scroll.asp" width="320" height="480" scrolling="no" marginheight="0" marginwidth="0">
    And the scroll.asp is


    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>
    </head>
    <body>
    <DIV ID="contentlayer" STYLE="position:absolute; width:320px; left: 0px; top: 0px">
    <img src="images/scroll.jpg" width=320 height=960>
    </div>
    </body>
    </html>
    Any idea why Firefox can't understand the reference?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    First of all, why in the world are you using eval( ) there???? You will get EXACTLY the same result without adding all the ugly overhead the eval() causes.

    Anywty, the root of your problem is the *ONLY* MSIE tends to treat names and ids the same.

    So only MSIE will take <iframe id="iframe"> and be able to find it via window.frames["iframe"]

    The correct form is window.frames[ name_of_frame ], not id_of_frame.

    But in any case, the most universal way to do this is REPLACE window.frames["iframe"] with document.getElementById("iframe")

    EDIT: And Chrome will let you get away with *SOME* MSIE-isms, but not all.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    conolan (10-13-2011)

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    103
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Hi,

    Try to fetch your iframe with document.getelementbyid and even try to give some other as iframe id like iframe1 etc.

  • #4
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Still not right.

    Eval is gone and iframe now named as well as id. Switched to this
    Code:
    var mypage= document.getElementById("iframe").contentlayer.style;
    Doesn't work in either IE or FF.

    FF reports >>> Error: document.getElementById("iframe").contentlayer is undefined

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    What is contentlayer?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor View Post
    What is contentlayer?
    DIV in the page within the iframe. MSIE recognises it.

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    var element=document.getElementById('iframe').contentWindow.document.getElementById('contentlayer');
    But it is not very clear if and why do you need to grab the style of that DIV. Do you need a certain CSS property from that style? Or what?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    conolan (10-13-2011)

  • #8
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Excellent, solved the problem, thanks.
    I'm adjusting the scroll of an image within the iframe.


  •  

    Posting Permissions

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