...

View Full Version : Firefox unable to identify iframe



conolan
10-13-2011, 07:31 AM
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

var mypage= eval(window.frames["iframe"].contentlayer.style);

My iframe is

<iframe id="iframe" src="scroll.asp" width="320" height="480" scrolling="no" marginheight="0" marginwidth="0">

And the scroll.asp is



<!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?

Old Pedant
10-13-2011, 07:40 AM
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.

jassi.singh
10-13-2011, 07:46 AM
Hi,

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

conolan
10-13-2011, 08:12 AM
Still not right.

Eval is gone and iframe now named as well as id. Switched to this

var mypage= document.getElementById("iframe").contentlayer.style;

Doesn't work in either IE or FF.

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

Kor
10-13-2011, 09:15 AM
What is contentlayer?

conolan
10-13-2011, 09:21 AM
What is contentlayer?

DIV in the page within the iframe. MSIE recognises it.

Kor
10-13-2011, 09:55 AM
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?

conolan
10-13-2011, 10:20 AM
Excellent, solved the problem, thanks.
I'm adjusting the scroll of an image within the iframe.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum