By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 2,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

Determine screensize

P: n/a
Hi,

I'm looking for a javascript that can give me the screensize of a computer.
Can anyone help me?

Thanks
Jun 9 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Joris De Groote wrote:
I'm looking for a javascript that can give me the screensize of a computer.
Can anyone help me?


alert(screen.width)

--
Bart

Jun 9 '06 #2

P: n/a
Joris De Groote wrote:
I'm looking for a javascript that can give me the screensize of a computer.
Can anyone help me?


alert(screen.height)

--
Bart

Jun 9 '06 #3

P: n/a
Joris De Groote wrote:
I'm looking for a javascript that can give me the screensize of a computer.
Can anyone help me?


Yes, you are mistaken in thinking that the screen size of a computer
has any relevance to anything you will do in a browser window with
javascript. You need to identify what you really need/want to know
before attempting to find out how to get that information.

Richard.

Jun 9 '06 #4

P: n/a
Richard Cornford wrote:
Yes, you are mistaken in thinking that the screen size of a computer
has any relevance to anything you will do in a browser window with
javascript.


I think you're being a bit obtuse.

Client request: "Please make the popup window appear in the middle of my
screen."

This requires knolwedge of screen resolution to implement.

There are cases where it fails (for example, dual monitors causes misleading
numbers) but in the majority of cases, it can be done.
If the OP knows the object/attributes to check and is aware that it may not
always be accurate in all cases, then he can make the decision himself of
whether or not it's appropriate for his situation.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 9 '06 #5

P: n/a
Matt Kruse wrote:
Richard Cornford wrote:
Yes, you are mistaken in thinking that the screen size of a computer
has any relevance to anything you will do in a browser window with
javascript.
I think you're being a bit obtuse.

Client request: "Please make the popup window appear in the
middle of my screen."

This requires knolwedge of screen resolution to implement.


But it also requires knowledge of the screen's disposition (and how
that disposition relates to and screen dimension information
available), and as that information is not exposed by browsers at all
the only honest way of satisfying the client is to ask them about their
specific screen, and tell them that others may not see the same as they
do.

The sensible response is to find out why the client thinks that opening
a window in the middle of the screen is a good idea and then offer them
something that will get the job done (which is probably making the user
aware of something important) in a reliable way that will turn out to
have no interest in screen dimensions.

A dialog opening in the middle of a monitor the user is not even
looking at does nobody any good, while presenting information in the
browser that the user is working with stands a very good chance of
bringing it to their attention.
There are cases where it fails (for example, dual monitors causes
misleading numbers) but in the majority of cases, it can be done.
You are forgetting pop-up blockers (not being able to open a window at
all).

You are also forgetting semi-permanent desktop features (such as the
task bar) which may significantly alter the value of putting a window
in the middle of the screen.

When choosing between options success in some majority of cases
combined with total failure in the rest is not as good a choice as
success in a larger proportions of cases and only degraded behaviour in
the rest. Bare in mind that picking on the standard dimensions
displayed on a 17 inch monitor will also 'work' in the vast majority of
cases. That really is not much of an achievement.
If the OP knows the object/attributes to check and is aware that it
may not always be accurate in all cases, then he can make the
decision himself of whether or not it's appropriate for his situation.


You want an informed decision, then what is wrong with telling someone
that they are mistaken in thinking that the screen size of a computer
has any relevance to anything they may want to do in a browser window?
If they are going to do it anyway knowing the required information is
either not available or not reliable then the dimensions did have no
relevance.

Richard.

Jun 9 '06 #6

P: n/a
Richard Cornford wrote:
the only honest way of satisfying the client is to ask them about
their specific screen, and tell them that others may not see the same
as they do.
Which may be acceptable. Maybe it's a webapp, and the browser/os
configuration is known. The requirement can be met.
The sensible response is to find out why the client thinks that
opening a window in the middle of the screen is a good idea and then
offer them something that will get the job done (which is probably
making the user aware of something important) in a reliable way that
will turn out to have no interest in screen dimensions.
Perhaps. Or maybe they want a popup to appear in the center of the screen!
A dialog opening in the middle of a monitor the user is not even
looking at does nobody any good
Agreed, so if dual monitors is the case, then another solution should
probably be found.
Also, dialogs aren't the only reason for wanting screen dimensions.

What if a webapp has a 'control panel' which they want to popup in the upper
right corner of the screen by default? What do you tell them? "Sorry, I
*could* do that, and it would work for all your users, but I don't want to,
because you shouldn't want that anyway."
You are forgetting pop-up blockers (not being able to open a window at
all). You are also forgetting semi-permanent desktop features
I'm not forgetting anything. Popping up a window is just one case where
screen dimensions might be handy.

Just because someone wants an answer doesn't mean they need to solve 100% of
possible cases. They may only be looking to solve a subset of all possible
conditions, which might be very doable.
When choosing between options success in some majority of cases
combined with total failure in the rest is not as good a choice
You're assuming that "total failure" is a possibility. Maybe it's not.
You want an informed decision, then what is wrong with telling someone
that they are mistaken in thinking that the screen size of a computer
has any relevance to anything they may want to do in a browser window?


If you told the OP some reasons why they might want to consider other
options, that might be helpful. Just telling them that they shouldn't do
what they think they want to do, with no reasoning behind it, is just
annoying.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 9 '06 #7

P: n/a
"Matt Kruse" <ne********@mattkruse.com> writes:
Perhaps. Or maybe they want a popup to appear in the center of the screen!
That should be discouraged. I use a browser with an MDI interface, so
it's pretty likely that the center of the screen is not available to
a web page window at all, and even if it is, positioning will almost
certainly fail.
What if a webapp has a 'control panel' which they want to popup in the upper
right corner of the screen by default?


Again, it would fail in my browser (but it might succeede in popping
up in the upper right corner of my browser application window).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 9 '06 #8

P: n/a
Lasse Reichstein Nielsen wrote:
Perhaps. Or maybe they want a popup to appear in the center of the
screen!

That should be discouraged.


Maybe in an internet context. But for an intranet or webapp, it might be
desired.
What if a webapp has a 'control panel' which they want to popup in
the upper right corner of the screen by default?

Again, it would fail in my browser (but it might succeede in popping
up in the upper right corner of my browser application window).


And my point was, if your browser environment was typical of one that needed
to be supported by the design, then popping up in any position would be a
bad idea. Otherwise, if the known browser environment would support such a
popup, it would work just fine.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 9 '06 #9

P: n/a
Matt Kruse wrote:
Richard Cornford wrote:
the only honest way of satisfying the client is to ask them
about their specific screen, and tell them that others may
not see the same as they do.
Which may be acceptable.


It is not supposed to be acceptable, it is intended to make it clear to
the individual with the ill-considered requirement that they are
thinking too much in terms of their personal situation and not
considering the bigger picture.

It is almost universal that individuals unconsciously assume that
everyone will interact with software in exactly the same way that they
do. Even putting aside accessibility considerations, the mindset that
has everyone using a mouse to interact with a browser makes proposal
that work with a mouse and disregards the possibility of keyboard use,
while there are plenty of individuals who will be preferring a keyboard
for interaction. It is part of the job of a software designer to take
their self-centred requirements and accommodate the unconsidered
alternatives in the resulting design.

If that requires that the individuals making the ill-thought-out
requirement be made to understand the real situation and maybe
re-state/word their requirement in a more suitable form then that is
what should happen. The customer may always be 'right', but the customer
should be employing someone else to design their software so that
process includes someone who knows which bigger picture needs to be
considered in the design.
Maybe it's a webapp, and the browser/os
configuration is known. The requirement can be met.
Doesn't the fact that a major factor in rendering screen dimensions
un-useful is the possibility of mult-monitor configurations require that
hardware configurations also be full known?
The sensible response is to find out why the client thinks
that opening a window in the middle of the screen is a good
idea and then offer them something that will get the job done
(which is probably making the user aware of something important)
in a reliable way that will turn out to have no interest in
screen dimensions.


Perhaps. Or maybe they want a popup to appear in the center of
the screen!


You are proposing that this is no more than an idle whim? Surly that is
only significant if it is a whim that is informed by an understanding
that its consequences may be poor or bad for some, otherwise making the
pertinent points may modify the whim into something more reasonable.
A dialog opening in the middle of a monitor the user is
not even looking at does nobody any good


Agreed, so if dual monitors is the case, then another
solution should probably be found.


And the only means of knowing whether multi-monitors is the case is
knowing the specific hardware in use, it cannot be reliably detected.
Also, dialogs aren't the only reason for wanting screen
dimensions.
The reasons for wanting to know screen dimensions mostly only exist in
the ignorance of the uselessness of the information those dimensions
represent.
What if a webapp has a 'control panel' which they want to
popup in the upper right corner of the screen by default?
It does not make sense to want your "control panel" to be placed where
it would be partly obscured by a task bar located to the left or top of
the display. Much as it does not make sense to put it in location where
the user may not be aware of its presence at all.

You may perceive the need for the screen dimensions in order to stratify
a poorly thought-out design, but fix the design an the interest in the
screen dimensions evaporates.
What do you tell them? "Sorry, I *could* do that, and it would
work for all your users, but I don't want to, because you
shouldn't want that anyway."
Why would I say that when in reality is may fail for any of their users?
You are forgetting pop-up blockers (not being able to open
a window at all). You are also forgetting semi-permanent
desktop features


I'm not forgetting anything.


Then why have you proposed the top-left of the screen as an appropriate
location for a "control panel"?
Popping up a window is just one case
where screen dimensions might be handy.
It is no, it is a case where thinking in terms of screen dimensions is
missing important aspects of reality.
Just because someone wants an answer doesn't mean they need
to solve 100% of possible cases.
And you think that is a reason for ignoring issues that can be
addressed?
They may only be looking to solve a subset of
all possible conditions, which might be very doable.


If people provide the context information related to their questions
then they may get answers tailored to that context, otherwise they get
what they get.
When choosing between options success in some majority
of cases combined with total failure in the rest is not
as good a choice


You're assuming that "total failure" is a possibility.
Maybe it's not.


There are so many possible failure scenarios following form actually
using browser reported screen dimensions that the few extremely
specialised cases where total failure is excluded cannot justify
brushing the issues aside without certain knowledge of the applicability
of the special case.
You want an informed decision, then what is wrong with
telling someone that they are mistaken in thinking that
the screen size of a computer has any relevance to anything
they may want to do in a browser window?


If you told the OP some reasons why they might want to
consider other options, that might be helpful. Just telling
them that they shouldn't do what they think they want to do,
with no reasoning behind it, is just annoying.


Above you are attempting to make the point that there are potentially a
wide range of conditions that may lead someone to believe that they
should have an interest in screen dimensions. Are you proposing that I
run through all of them (or at lest the couple of dozen that may come to
mind at any the time) and enumerate the issues, possibilities and
alternatives for each?

It makes much more sense to me to propose that the question implies a
fundamental misconception and leave it to the OP to render the situation
concrete enough for practical strategies to be proposed.

And what alternative are you proposing? Someone spitting out -
screen.width/height - and leaving the OP to add yet another poorly
though-out script to the Internet?

Richard.
Jun 11 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.