Problem with contentWindow - returns different object in FF and IE

S

szimek

Hi,
I've got a page with an iframe:

<iframe id="commframe" src="../webclient/common/hiddenframe.jsp">

then there's the following code:

var commframe =
document.getElementById("commframe").contentWindow.document;

Now in FF commframe is ../webclient/common/hiddenframe.jsp, while in
IE it's ../ui/main.jsp.

I'm trying to make an IE-only web page to work in other browsers. This
js code is from a general function that is called by many of elements,
so I can't simply get the document by name or something - it must be
very general.

Any ideas what's wrong? Thanks in advance
 
S

szimek

Hi,
I've got a page with an iframe:

<iframe id="commframe" src="../webclient/common/hiddenframe.jsp">

then there's the following code:

var commframe =
document.getElementById("commframe").contentWindow.document;

Now in FF commframe is ../webclient/common/hiddenframe.jsp, while in
IE it's ../ui/main.jsp.

I'm trying to make an IE-only web page to work in other browsers. This
js code is from a general function that is called by many of elements,
so I can't simply get the document by name or something - it must be
very general.

Any ideas what's wrong? Thanks in advance
A bit more information:
- inside hiddenframe.jsp there's <base href="../ui/"> in the <head>
- it works fine on Opera 9.2 (I didn't check what exectly the
commframe variable is set to, but does what it should do)
 
G

GArlington

Hi,
I've got a page with an iframe:

<iframe id="commframe" src="../webclient/common/hiddenframe.jsp">

then there's the following code:

var commframe =
document.getElementById("commframe").contentWindow.document;

Now in FF commframe is ../webclient/common/hiddenframe.jsp, while in
IE it's ../ui/main.jsp.

Now, I tried something similar (just with HTML src for the iframe) and
it works all in IE6 and FF2.
Are you doing conditional (browser dependent) redirect in your ../
webclient/common/hiddenframe.jsp?
 
S

szimek

GArlington napisa³(a):
Now, I tried something similar (just with HTML src for the iframe) and
it works all in IE6 and FF2.
Are you doing conditional (browser dependent) redirect in your ../
webclient/common/hiddenframe.jsp?
Thanks for answering.

Unfortunately I'm not doing any browser dependend redirects as this
app was written for IE only. I've noticed that there's a form in
hiddenframe.jsp that has action="../ui/main.jsp" - that's the only
place where "main,jsp" file is referenced. The strange thing is that
it works fine in Opera, but I need to check what exectly is happening
there. I thought that maybe there's some known issue with
contentWindow in IE or FF. I'll try to check what exactly is happening
in Opera in this part of code, maybe it will help.
 
S

SAM

szimek a écrit :
Hi,
I've got a page with an iframe:

<iframe id="commframe" src="../webclient/common/hiddenframe.jsp">

then there's the following code:

var commframe =
document.getElementById("commframe").contentWindow.document;

Now in FF commframe is ../webclient/common/hiddenframe.jsp, while in
IE it's ../ui/main.jsp.

I'm trying to make an IE-only web page to work in other browsers. This
js code is from a general function that is called by many of elements,
so I can't simply get the document by name or something - it must be
very general.

Any ideas what's wrong? Thanks in advance


what gives

function $(id) { return document.getElementById(id); }

var commframe = !($("commframe").document &&
$("commframe").document.location)?
$("commframe").src : $("commframe").document.location;

alert(commframe);
 
V

VK

Hi,
I've got a page with an iframe:

<iframe id="commframe" src="../webclient/common/hiddenframe.jsp">

then there's the following code:

var commframe =
document.getElementById("commframe").contentWindow.document;

Such convoluted DOM1-based way is indeed suggested in many manuals but
I would strongly suggest to drop it for a number of peculiarity issues
across different UAs. Use DOM0 and NAME instead of ID and be always
happy:

<iframe name="commframe" src="../webclient/common/hiddenframe.jsp">

function init() {
// called on main document load
// but not before that of course,
// that may be another problem in
// your case:
var cframe = self.frames['commframe'].document;
}
 
S

szimek

Hi,
I've got a page with an iframe:
<iframe id="commframe" src="../webclient/common/hiddenframe.jsp">
then there's the following code:
var commframe =
document.getElementById("commframe").contentWindow.document;

Such convoluted DOM1-based way is indeed suggested in many manuals but
I would strongly suggest to drop it for a number of peculiarity issues
across different UAs. Use DOM0 and NAME instead of ID and be always
happy:

<iframe name="commframe" src="../webclient/common/hiddenframe.jsp">

function init() {
 // called on main document load
 // but not before that of course,
 // that may be another problem in
 // your case:
 var cframe = self.frames['commframe'].document;

}

Thanks a lot guys!
It turned out that the commframe was used many lines below to fetch a
form from the hiddenframe.jsp. This form had only name attribute, no
id, that's why it worked in IE and Opera (which tries to be more
compatible by introducing IE bug to getElementById). I've added id
attribute to the form and it passed this part of the code smoothly. It
breaks few lines later again, but that's a different story :)
 
T

Thomas 'PointedEars' Lahn

VK said:
<iframe id="commframe" src="../webclient/common/hiddenframe.jsp">

then there's the following code:

var commframe =
document.getElementById("commframe").contentWindow.document;

Such convoluted DOM1-based way is indeed suggested in many manuals [...]

The `contentWindow' property of *iframe* objects is not part of any W3C DOM
Specification, including the (obsolete) W3C DOM Level 1.

http://msdn2.microsoft.com/en-us/library/ms533692(VS.85).aspx
http://www.mozilla.org/docs/dom/domref/dom_frame_ref5.html
var cframe = self.frames['commframe'].document;

`self' is a proprietary property of a proprietary host object in the scope
chain that *might* implement properties of equally proprietary Window
objects. It is therefore better to use `window' instead.


PointedEars
 

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,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top