Kirill Tchourioukanov

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromKirill Tchourioukanov
ToMe
SubjectObtaining the browser window size in Safari?
Date17 March 2004 17:32
Mark,


 Your great JavaScript 'Obtaining the browser window size'
doesn't work properly in Safari.
http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

It doesn't work when used inside an IFrame.

it works fine inside an IFrame using innerWidth and innerHeight one
out of 100 times.

 Can you give me some suggestions?


 Thanks a lot for your site.

 Kirill
FromMe
ToKirill Tchourioukanov
SubjectRe: Obtaining the browser window size in Safari?
Date17 March 2004 19:33
Kirill,

I don't have my mac to hand at the moment, so I got some mates on 
chat to test for me. You are quite right, Safari always says 0x0 in an
iframe. I will check tomorrow if there is anything I can do to make it
work for you.

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromMe
ToKirill Tchourioukanov
SubjectRe: Obtaining the browser window size in Safari?
Date18 March 2004 11:39
Kirill,

I have found a 'solution' to the problem.

First I tried using the document.body properties, but it also gets them
wrong, so I could not produce an easy fix. I have reported this to Apple,
because it is a bug in their Safari browser. Hopefully they will fix it in
a future release.

However, I did notice something strange:

The page that is loaded into the iframe using the src attribute of the
iframe will not work. However, if that page loads another page into the
iframe, using a link or script, then the second page that loads will get it
right.

This is the 'solution' (not a good solution - more of a hack):
<iframe height="blah" width="blah" src="fwd.html"></iframe>

then in 'fwd.html'
<script type="text/javascript"><!--
location.replace('thePageYouWantedToBeInTheIframe.html');
//--></script>

I know this is not a perfect solution, but if you really need Safari
support, this is the only thing you can do.

Hope you find this useful.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromKirill Tchourioukanov
ToMe
SubjectRe: Obtaining the browser window size in Safari?
Date18 March 2004 14:49
Mark,

WOW! Don't we think alike or what? I've tried exactly the same hack
[the document.body hack]
before writing to you. And it didn't work. I found a mistake...

Thanks a LOT! I'll be contacting you in the future for such extraordinary
advices, may I?

Kirill
FromKirill Tchourioukanov
ToMe
SubjectRe: Obtaining the browser window size in Safari?
Date18 March 2004 15:09
Mark,

Also, I'd suggest the following code. It works better in IE 6+.
I added the section for offsetWidth and offsetHeight.

function alertSize() {
  var myWidth = 0, myHeight = 0;
  //try window.innerBlah
	//else try body.offsetBlah
	//else try body.clientBlah
	//else try documentElement.clientBlah
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

Thanks again.

Kirill
FromMe
ToKirill Tchourioukanov
SubjectRe: Obtaining the browser window size in Safari?
Date18 March 2004 15:23
Kirill,

Of course you are welcome to contact me again.

Note, I have not yet found a situation where my window size script does not
work in IE6. What you sent me should work (using offset properties), but in
fact can cause problems if the content is smaller than the window under
certain circumstances.

Unless I find a situation where my script causes problems, I intend to
leave it as it is, just with a note about Safari. Thanks for the info
anyway.

Tarquin
FromKirill Tchourioukanov
ToMe
SubjectRe: Obtaining the browser window size in Safari?
Date18 March 2004 15:31
Mark,

Don't forget I'm using it inside IFrames. When I use your script 'as is' in
IE 6+ it gives me the dimensions 4 pixels smaller then actual using
documentElement. My version seems to be working properly even with empty
document.

Let me know what you think.

Thanks.

Kirill
FromMe
ToKirill Tchourioukanov
SubjectRe: Obtaining the browser window size in Safari?
Date18 March 2004 15:57
This is true, but it can happen if your iframe contains borders. It also is
sometimes affected by padding or margins on the body or HTML tags, or by
the existence of scrollbars.

I have covered similar problems extensively in a previous email:
http://www.howtocreate.co.uk/emails/BrynDyment.html

The problem with using offset does not lie with using IE6, it is with older
browsers that also provide offsetBlah, but get it wrong, or where it
relates to content, not window size.
FromKirill Tchourioukanov
ToMe
SubjectRe: Obtaining the browser window size in Safari?
Date18 March 2004 16:08
Mark,

OK. The problem only if IFrame has a border. Your version handles IFrames
without a border properly.

Kirill
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.