View Full Version : JS that detects screen res. and displays msg according to res.
I found this script at crows java scripts:
<SCRIPT LANGUAGE="Javascript"><!--
if (self.screen) { // for NN4 and IE4
width = screen.width
height = screen.height
// Testing this first prevents firing the slow Java of NN4
}
else if (self.java) { // for NN3 with enabled Java
var jkit = java.awt.Toolkit.getDefaultToolkit();
var scrsize = jkit.getScreenSize();
width = scrsize.width;
height = scrsize.height;
}
else{
width = height = '?' // N2, E3, N3 w/Java off, probably Opera and WebTV
}
document.write(width +"×"+ height)
//or whatever based on the above results
//--></SCRIPT>
This script detects screen res. and prints it on page. Can anyone modify it so that say if it detected 800*600 then it would display a msg. "Please increase your screen resolution before viewing our site" and if it detected 1024*768 it would display "Your monitor is calibrated correctly, please continue".
There is also one at crows that detects olour depth which would be good to alter aswell.
http://www.crows.co.uk/Javascript/
cheers
------------------
Rigo
erm...just a small point
If I went to a site that told me to change my screen res to suit it, my visit would end right there!
You have to cater for your audience, not tell them what to do.
Just my opinion.
okay maybe the messages where a bit strong, i could say "we suggest you increase your res. to view this site"
Maybe something like that
------------------
Rigo
Banana Man
24-05-2000, 18:40
or.......
have two styles of the same site, one for 800x600, one for 1024
the script could redirect accordingly
in if someones only got 640x480 it could say "sorry your computer is too sh1te, go away"
yeah there is also a script that redirects but i'll have to make the site in two different resolutions and that's just hard work.
Try working in 800*600 on a 17", not v easy
and for the 640*480 bit of code you said, it would need what i'm asking for anyway :)
------------------
Rigo
All sites should work in all resolutions from 640x480 upwards IMO, if yours doesn't then it's bad design.
of course it "works" in all resolutions but you have to srcoll across to see all of it :)
i can make it into 800*600 but it looks cramped up and all bundled together.
Hey at least i have consideration for people in lower resolutions, some sites don't care and just make it in 1024*768. I used to have an old sh*tty monitor that was only capable of 800*600 max and I know how annoying it is to have to scroll horizontally aswell as vertically.
I don't mean to have a go or anything, this would just be a good way to work around a problem, that's all.
------------------
Rigo
Banana Man
24-05-2000, 23:24
if you use SSI's then you only need to do the content once, just design a different interface for peeps wiv lower resolutions
<BLOCKQUOTE><font size="1" face="Verdana">quote:</font><HR>Originally posted by Rigo:
Can anyone modify it so that say if it detected 800*600 then it would display a msg. "Please increase your screen resolution before viewing our site" and if it detected 1024*768 it would display "Your monitor is calibrated correctly, please continue".
cheers
<HR></BLOCKQUOTE>
Well like peeps have said above its not very 'pro' to ask people to change resolutions so a low res version could be redirected to like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<SCRIPT LANGUAGE="Javascript"><!--
var bLowres; //flag for low res
var bOptimalres; //flag for optimal res
bLowres=false;
bOptimalres=false;
if (self.screen) { // for NN4 and IE4
width = screen.width
height = screen.height
// Testing this first prevents firing the slow Java of NN4
}
else if (self.java) { // for NN3 with enabled Java
var jkit = java.awt.Toolkit.getDefaultToolkit();
var scrsize = jkit.getScreenSize();
width = scrsize.width;
height = scrsize.height;
}
else{
width = height = '?' // N2, E3, N3 w/Java off, probably Opera and WebTV
}
//document.write(width +"×"+ height)
//or whatever based on the above results
if(width<=800 | | height<=600)
{
bLowres=true;
document.write('<META HTTP-EQUIV="Refresh" CONTENT="6; URL=http://myserver/lowres.html">');
}
else if(width==1024 && height==768)
{
bOptimalres=true;
}
//--></SCRIPT>
<title>Test Page</title>
</head>
<body>
Your screen resolution is
<SCRIPT LANGUAGE="Javascript"><!--
document.write(width +"×"+ height+"<BR><BR>");
if(bLowres==true)
{
document.write('Please wait while we redirect you to the low res version of the site...');
}
else if(bOptimalres==true)
{
document.write('Your browser is the optimal resolution for this site');
}
//--></SCRIPT>
</body>
</html>
http://forums.gameplay.com/ubb/teeth.gif
Web http://forums.gameplay.com/ubb/monkee.gif
[This message has been edited by Peach (edited 25-05-2000).]
yeah i do use SSI but it does look kinda cramped up.
Peach > That script looks like the sort thing I could use, only thing is it don't work properly, I get a JS error when trying to run it in IE5. Can this be sorted?
Thanks very much for your time and help everyone.
------------------
Rigo
The problem is the two | symbols in the line of the script that starts if(width<=.. get a space put between them by UBB when I submit :(
Just take the space out so there is nothing between them and that sorts it.
HTH
peach > that works a treat m8, cheers :)
I dunno how you managed to track the problem down to one space, you must work as a java programmeur and loads of money. One day maybe I may follow in your footsteps ;)
cheers again
------------------
Rigo
yeah this was double post too.
------------------
Rigo
[This message has been edited by Rigo (edited 26-05-2000).]
I wouldn't exactly say 'loads'... ;)
Glad I could help :)
dbl post shambles
[This message has been edited by Peach (edited 26-05-2000).]
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.