469,293 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,293 developers. It's quick & easy.

Hi, can this be done? [determining size of specified browser window]

Is there anyway to determine the present pixel height & width size of a
open browser window? :)

Nov 2 '06 #1
19 1931
ca******@gmail.com said the following on 11/1/2006 8:47 PM:
Is there anyway to determine the present pixel height & width size of a
open browser window? :)
Yes.

Your first Hint is that it is covered in the FAQ.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 2 '06 #2
and the second is check out randy's signature .....

Nov 2 '06 #3
Thank you for that. The only example that partially works (IE >6.0,
XP) is:

<script>

var winWidth = document.documentElement.clientWidth
var winHeight = document.documentElement.clientHeight
alert(winWidth)
alert(winHeight)

</script>

The winHeight comes back as 0.... the other examples show undefined....
is there something I am parsing wrong here? :)

Nov 2 '06 #4
ca******@gmail.com said the following on 11/2/2006 3:18 PM:
Thank you for that. The only example that partially works (IE >6.0,
XP) is:

<script>

var winWidth = document.documentElement.clientWidth
var winHeight = document.documentElement.clientHeight
alert(winWidth)
alert(winHeight)

</script>

The winHeight comes back as 0.... the other examples show undefined....
is there something I am parsing wrong here? :)
Yes.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 2 '06 #5
Can you please provide a working solution? Thank you!

Nov 2 '06 #6
Hmm, ok, then it appears your FAQ has unworking examples. What is the
working solution you don't mind sharing with the group? Thank you.
Best regards, Kat

Nov 2 '06 #7
ca******@gmail.com said the following on 11/2/2006 5:50 PM:
Hmm, ok, then it appears your FAQ has unworking examples.
It does? Where? The code in the FAQ does precisely what the FAQ says it
will do.
What is the working solution you don't mind sharing with the group?
"Working solution" to what?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 2 '06 #8

I'm very sorry Randy - If I take your words at face-value you are
saying in my earlier message that "Yes." I am parsing something
wrong?.... the code I presented in my prior message was a cut-and-paste
from your FAQ. I get the width demension but not the height, which
comes back as 0. The other examples don't work at all.... in Firefox
or IE 6.0 & 7.0. I might be overlooking something. When you say Yes,
can you articlate my misunderstanding? :)

Nov 3 '06 #9
TC

ca******@gmail.com wrote:
I'm very sorry Randy -
He's not interested in helping you. Perhaps you did not genefluct
correctly.

Try here:
http://msdn.microsoft.com/library/de.../measuring.asp

Remember the 'type' attribute in your <scriptelements:
<script type="text/javascript">

HTH,
TC (MVP MSAccess)
http://tc2.atspace.com

Nov 3 '06 #10

ca******@gmail.com wrote:
I'm very sorry Randy - If I take your words at face-value you are
saying in my earlier message that "Yes." I am parsing something
wrong?.... the code I presented in my prior message was a cut-and-paste
from your FAQ.
The problem isn't the code, it's when you call it. Wrap it in a
function and call it onload, then it will "work" in IE too:

function foo(){
var winWidth, winHeight, d=document;
if (typeof window.innerWidth!='undefined') {
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} else if ( d.documentElement
&& typeof d.documentElement.clientWidth!='undefined'
&& d.documentElement.clientWidth!=0 ) {
winWidth = d.documentElement.clientWidth;
winHeight = d.documentElement.clientHeight;
} else if ( d.body
&& typeof d.body.clientWidth!='undefined') {
winWidth = d.body.clientWidth;
winHeight = d.body.clientHeight;
}
alert('winWidth: ' + winWidth
+ '\nwinHeight: ' + winHeight);
}

window.onload = foo;

--
Rob

Nov 3 '06 #11
super-hawaii-, i see top quality job at microsoft msdn department in
your future :)
RobG wrote:
ca******@gmail.com wrote:
I'm very sorry Randy - If I take your words at face-value you are
saying in my earlier message that "Yes." I am parsing something
wrong?.... the code I presented in my prior message was a cut-and-paste
from your FAQ.

The problem isn't the code, it's when you call it. Wrap it in a
function and call it onload, then it will "work" in IE too:

function foo(){
var winWidth, winHeight, d=document;
if (typeof window.innerWidth!='undefined') {
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} else if ( d.documentElement
&& typeof d.documentElement.clientWidth!='undefined'
&& d.documentElement.clientWidth!=0 ) {
winWidth = d.documentElement.clientWidth;
winHeight = d.documentElement.clientHeight;
} else if ( d.body
&& typeof d.body.clientWidth!='undefined') {
winWidth = d.body.clientWidth;
winHeight = d.body.clientHeight;
}
alert('winWidth: ' + winWidth
+ '\nwinHeight: ' + winHeight);
}

window.onload = foo;

--
Rob
Nov 3 '06 #12

ca******@gmail.com wrote:
Thank you for that. The only example that partially works (IE >6.0,
XP) is:

<script>

var winWidth = document.documentElement.clientWidth
var winHeight = document.documentElement.clientHeight
alert(winWidth)
alert(winHeight)

</script>

The winHeight comes back as 0.... the other examples show undefined....
is there something I am parsing wrong here? :)
Kat, tha problem may be in CSS. If you using standards-compilant mode
then you might set height of the page to 100%
<style type='text/css'>
HTML,BODY {height:100%}
</style>

Val Polyakh,
http://trickyscripter.com

Nov 3 '06 #13
TC said the following on 11/3/2006 12:35 AM:
ca******@gmail.com wrote:
>I'm very sorry Randy -

He's not interested in helping you.
I helped in more ways than one. The fact that neither of you realize
that says something in and of itself.
Perhaps you did not genefluct correctly.
Sesquipedalian behavior is a sign of ignorance, not intelligence.
Try here:
http://msdn.microsoft.com/library/de.../measuring.asp
Yeah, that shows how to get the dimensions of the browser window - it
doesn't. Yet the reference I referred them to (in this groups FAQ) does
precisely what was asked for. Who is it that isn't helping?
Remember the 'type' attribute in your <scriptelements:
<script type="text/javascript">
And then remember that it's irrelevant to the question? The DTD makes
more difference than the type attribute ever will.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 3 '06 #14
Randy Webb schreef:
TC said the following on 11/3/2006 12:35 AM:
>ca******@gmail.com wrote:
>>I'm very sorry Randy -

He's not interested in helping you.

I helped in more ways than one. The fact that neither of you realize
that says something in and of itself.
>Perhaps you did not genefluct correctly.

Sesquipedalian behavior is a sign of ignorance, not intelligence.
>Try here:
http://msdn.microsoft.com/library/de.../measuring.asp

Yeah, that shows how to get the dimensions of the browser window - it
doesn't. Yet the reference I referred them to (in this groups FAQ) does
precisely what was asked for. Who is it that isn't helping?
>Remember the 'type' attribute in your <scriptelements:
<script type="text/javascript">

And then remember that it's irrelevant to the question? The DTD makes
more difference than the type attribute ever will.
http://whatsmy.browsersize.com/
Nov 4 '06 #15
ar*********@nietbereikbaar.nl said the following on 11/4/2006 1:31 PM:
Randy Webb schreef:
>TC said the following on 11/3/2006 12:35 AM:
>>ca******@gmail.com wrote:
I'm very sorry Randy -

He's not interested in helping you.
<snip>
http://whatsmy.browsersize.com/
All that does is prompt me to install some Java Applet that I don't care
to install.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 4 '06 #16
VK
ca******@gmail.com wrote:
Is there anyway to determine the present pixel height & width size of a
open browser window? :)
No (with the default security settings). This "No" is relevant to the
literal interpretation of your question: "can I find out pixel size of
application window I'm seeing on my monitor".

The <http://jibbering.com/faq/#FAQ4_9(which what you seem used) is
irrelvant to your question as interpreted above.

<FAQENTRY>
http://jibbering.com/faq/#FAQ4_9 is called "How do I find the size of a
browser window?" while it is about of determining the working area of a
document open in a browser window.
</FAQENTRY>

Unless it's a specially made newcomer's trap for dansing around the
caught victimes (like Mr.Webb just demonstrated) - unless that the FAQ
title has to be re-phrased to something more corresponding to its topic.

Nov 5 '06 #17
"RobG" <rg***@iinet.net.auwrites:
The problem isn't the code, it's when you call it. Wrap it in a
function and call it onload, then it will "work" in IE too:
[...]
And now for a bonus points: Is there way to know the DPI of the screen
in which the user agent runs?

I found this :

----------snip-----------
By the way there is already a simple way to detect DPI in JavaScript,
provided that the OS and browser implement them right: Create a div
with width=height=1in, then query it¡Çs pixel size
(offsetWidth/offsetHeight). That is the real ¡Èdots per inch¡É, and I
am sorry if the browser feel the need to mess that up.
---------/snip-----------

at the following address: http://webkit.org/blog/?p=55 (in one of the comments)

...but is there any other way?

Thank you,
Arnaud
function foo(){
var winWidth, winHeight, d=document;
if (typeof window.innerWidth!='undefined') {
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} else if ( d.documentElement
&& typeof d.documentElement.clientWidth!='undefined'
&& d.documentElement.clientWidth!=0 ) {
winWidth = d.documentElement.clientWidth;
winHeight = d.documentElement.clientHeight;
} else if ( d.body
&& typeof d.body.clientWidth!='undefined') {
winWidth = d.body.clientWidth;
winHeight = d.body.clientHeight;
}
alert('winWidth: ' + winWidth
+ '\nwinHeight: ' + winHeight);
}

window.onload = foo;

--
Rob
--
Arnaud DIEDEREN
Software Developer
IONIC Software
Rue de Wallonie, 18 - 4460 Grace-Hollogne - Belgium
Tel: +32.4.3640364 - Fax: +32.4.2534737
mailto:ad@ionicsoft.com
http://www.ionicsoft.com
Nov 7 '06 #18
Arnaud Diederen (aundro) said the following on 11/7/2006 7:58 AM:
"RobG" <rg***@iinet.net.auwrites:
>The problem isn't the code, it's when you call it. Wrap it in a
function and call it onload, then it will "work" in IE too:
[...]

And now for a bonus points: Is there way to know the DPI of the screen
in which the user agent runs?
You ask a question and then give an answer?
I found this :

----------snip-----------
By the way there is already a simple way to detect DPI in JavaScript,
provided that the OS and browser implement them right: Create a div
with width=height=1in, then query it’s pixel size
(offsetWidth/offsetHeight). That is the real “dots per inch”, and I
am sorry if the browser feel the need to mess that up.
"mess that up" in what way?

A better question is "Why does the DPI matter in a WWW context?"

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 7 '06 #19

Hi,

Randy Webb <Hi************@aol.comwrites:
You ask a question and then give an answer?
I give _one possible_ answer, but I don't know if that's really
reliable and/or whether there are any other answers :)
>
>I found this :

----------snip-----------
By the way there is already a simple way to detect DPI in JavaScript,
provided that the OS and browser implement them right: Create a div
with width=height=1in, then query it's pixel size
(offsetWidth/offsetHeight). That is the real 'dots per inch', and I
am sorry if the browser feel the need to mess that up.

"mess that up" in what way?
Since that quoted text is part of the 'solution' I found (in the
comments at http://webkit.org/blog/?p=55) and therefore I didn't write
it, I can only presume he/she meant that the browser might not
properly implement the CSS 'inch-based' rules computations.

>
A better question is "Why does the DPI matter in a WWW context?"
Because I'm into GIS (Geographic Information Systems) web
applications, and in order to give the user a relevant 'scale' of,
say, a 800x600 map/image, it would be appropriate to know the size (in
inches) of that map/image. So far, I can only approximate a scale,
using a fixed DPI.

Arnaud.

>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
--
Arnaud DIEDEREN
Software Developer
IONIC Software
Rue de Wallonie, 18 - 4460 Grace-Hollogne - Belgium
Tel: +32.4.3640364 - Fax: +32.4.2534737
mailto:ad@ionicsoft.com
http://www.ionicsoft.com
Nov 10 '06 #20

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Johnny Knoxville | last post: by
reply views Thread by Jan Roland Eriksson | last post: by
6 posts views Thread by scottyman | last post: by
3 posts views Thread by Steve Sobol | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.