Forum Moderators: open

Message Too Old, No Replies

measure parent window size

ignoring contained iframes to assess screen user width

         

gleddy

11:48 pm on Jan 31, 2005 (gmt 0)

10+ Year Member



hi,

related to another problem I recently posted I have narrowed down my problem.

I have to measure the users browser window and need to do this on some pages that contain Iframes within them...

The code I have now works in Firefox, but for some reason IE does not like it when there is an Iframe within the <body> tag.

anyone have any ideas? thanks in advance for any advice, really stuck on this one!

=====

<html>
<head>
<title>Iframe - measure window test</title>
</head>

<body onload="checkRightPanel();">

<script language="javascript" type="text/javascript">
<!--
window.onresize= checkRightPanel;

function checkRightPanel() {
userWidth = document.getElementsByTagName('body')[0].clientWidth;
if (userWidth >= 800) {
alert("big measure");
} else {
alert("small measure");
}
}
//-->
</script>

<!-- iframe start -->
<iframe width="500" height="240" src="http://www.webmonkey.com">
</iframe>
<!-- iframe end -->

</body>
</html>

Bernard Marx

12:00 am on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure I understnad the problem.
That is to say the reported clientWidth is accurate whether the page cntains an Iframe or not (IE6 Win 2K).

gleddy

12:29 am on Feb 1, 2005 (gmt 0)

10+ Year Member



the problem is that the iframe is interfering with the function in IE.

for example:

in Firefox or Netscape, when loading this page, upon resizing the window the alert box will always tell you whether you are in a 'small size' or 'big size' (assessing if the browser greater of less than 800px wide).

when the same page is loaded into IE, it does not respond. I have tested this and it is only when the iframe is present in the code.

this is a dumbed down version of what I am trying to achieve, but this is the problem I have run into.

cheers...

Bernard Marx

12:44 am on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I ran the code you posted (#1) in IE6, and it works fine.
(oh...haven't checked resizing yet)
Yup. That's OK too.

gleddy

12:51 am on Feb 1, 2005 (gmt 0)

10+ Year Member



really?

are you getting the popup window alerts as well?

with the iframe in the code?

Bernard Marx

12:55 am on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes.

gleddy

1:01 am on Feb 1, 2005 (gmt 0)

10+ Year Member



man. I am stumped then. guess I will try to get some friends to test in IE as well as I still can't get any action in IE on this machine. hopefully it's just me in the end.

thanks for the help, bernard :-)

s.

gleddy

1:39 am on Feb 1, 2005 (gmt 0)

10+ Year Member



o.k. wierd.

I just removed the webmonkey url and replaced with another and it works fine! hmmmm. there's one to think about.

thanks for helping! all good.

gleddy

1:55 am on Feb 1, 2005 (gmt 0)

10+ Year Member



one last question...

after testing some url's in the source for the iframe I am getting mixed results in IE (Firefix etc are still fine)...

about 50/50 for success depending on the url that is provided for the iframe content.

does this make any sense? is the iframe pulling in any code that could possibly be conflicting with my javascript in IE?

cheers....

Rambo Tribble

2:45 am on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there any connection between the URL being from your domain or external, and the observed behavior?

gleddy

3:04 am on Feb 1, 2005 (gmt 0)

10+ Year Member



i don't think so...

it's just the iframe seems to be interfering with my show div / hide div function (alert boxes in this test code...).

realistically, there is not going to be an iframe in all instances of this web page, but I know that there will be some. so I am trying to cover for these instances.

so I am using a staging base href for initial testing, and I realize this might not work. so I have gone back and played with different urls in the iframe src.

ex.
[webmonkey.com...] => doesn't work
[different.com.au...] => works fine

is this what you mean?

Bernard Marx

12:04 pm on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a stab in the dark..

The page's onload event doesn't fire until everything has loaded, including the content of the iframe. It looks like - for whatever reason - your browser has a problem loading certain iframe content, and the

onload
event never fires. We might as well work something out that doesn't rely on this event at all.

The simplest way to do this is to call the function from within a small script block just inside the BODY (that way, we know the BODY exists before referencing it):

<script>checkRightPanel()</script>

If the eventual script is also referencing other document elements, this script block could move to become the last element in the BODY instead.

This method has another advantage over using an

onload
event listener. This is that the "initiation" procedure is called as soon as all the relevant elements are available, whilst an
onload
will wait for all content to download. If there are some heavy images this could be a few seconds later.

This method does, however, break with the purist "separate behaviour from content" ideal. There is another method which allows all scripting to be kept in external files, but it involves running a cancellable loop that checks for the existence of elements before acting upon them. Maybe too much bother for purity's sake.

gleddy

12:44 pm on Feb 1, 2005 (gmt 0)

10+ Year Member



I really think you are on too something with that one...

I removed the checkRightPanel() from the onload event and stuck it in the body as you suggested. It did not solve my error yet, but I did stick an alertMe() function in the onload event (just to check if the onload completed).

With the problematic urls the page does not completely download as you have said. The onload event never triggers.

So ideally the script:
<script>checkRightPanel()</script>
should cure that problem. but it still doesn't seem to for some reason.

Will try tomorrow with this at work in the live environment and let you know how it goes. Here's hoping it just fixes itself :-)

cheers!