...

View Full Version : about how to detecting user screen size



wilbasket168
08-23-2002, 07:41 PM
hello question how to write a script to determine the user screen size so my home page can dectect the user resolution size and display the correct resolution size web pages

x_goose_x
08-23-2002, 10:16 PM
Not sure if I'm understanding you but try this:



<script>
w=screen.width;
h=screen.height;
if (w==640&&h==480) {
location.replace("640.htm");
}else if (w==800&&h==600) {
location.replace("800.htm");
}else if (w==1024&&h==768) {
location.replace("1024.htm");
}else if (w==1152&&h==864) {
location.replace("1152.htm");
}else if (w==1280&&h==1024) {
location.replace("1280.htm");
}else{
location.replace("unknown.htm");
}
</script>

Skyzyx
08-24-2002, 02:55 AM
Well, this may seem a bit complicated, but I wrote this script to give me alot of flexibility with little coding.



/*************************
SCREEN RESOLUTION
**************************/
// DECLARE THE ARRAY
var resolution = new Array();

// GET W&H VALUES
var wide=screen.width;
var high=screen.height;

// EXACT RESOLUTION SCRIPT
function xRes()
{
var wide=screen.width; // How wide is your screen? (Larger number than Height)
var high=screen.height; // How tall is your screen? (Smaller number than Width)
var display=wide+' x '+high;

return display;
}

// RESOLUTION IS EXACTLY THIS SIZE
resolution.is640x480=(wide==640 && high==480) ? true:false;
resolution.is800x600=(wide==800 && high==600) ? true:false;
resolution.is832x624=(wide==832 && high==624) ? true:false;
resolution.is1024x768=(wide==1024 && high==768) ? true:false;
resolution.is1152x870=(wide==1152 && high==870) ? true:false;
resolution.is1280x1024=(wide==1280 && high==1024) ? true:false;
resolution.is1600x1200=(wide==1600 && high==1200) ? true:false;

// RESOLUTION IS THIS SIZE OR BIGGER
resolution.min640x480=(wide>=640 && high>=480) ? true:false;
resolution.min800x600=(wide>=800 && high>=600) ? true:false;
resolution.min832x624=(wide>=832 && high>=624) ? true:false;
resolution.min1024x768=(wide>=1024 && high>=768) ? true:false;
resolution.min1152x870=(wide>=1152 && high>=870) ? true:false;
resolution.min1280x1024=(wide>=1280 && high>=1024) ? true:false;
resolution.min1600x1200=(wide>=1600 && high>=1200) ? true:false;

// THIS WILL RETURN THE USERS EXACT RESOLUTION
resolution.size=xRes();


You could use this stuff in the following manner:



if (resolution.is800x600) // If resolution is exactly 800x600
{
location.href='800x600.htm';
}
else if (resolution.is1024x768) // If resolution is exactly 1024x768
{
location.href='1024x768.htm';
}
else if (resolution.min1152x870) // If resolution is AT LEAST this size
{
location.href='1152up.htm';
}


Or, you could use the last command...



document.write('Your screen resolution is '+resolution.size);


Hope this helps!

sir pannels
09-27-2003, 11:40 AM
Hey,
found this old post and trying this...


<script>
w=screen.width;
h=screen.height;
if (w==640&&h==480) { location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=450");
}else if (w==800&&h==600) { location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=450");
}else if (w==1024&&h==768) { location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=620");
}else if (w==1152&&h==864) { location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=800");
}else if (w==1280&&h==1024) { location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=850");}
</script>

but it doesnt seem to work, it just doesnt redirect anwhere, like its just ignoring it.

Anyone have any ideas?
cheers
P:confused:

me'
09-27-2003, 12:56 PM
Either...

screen.width and screen.height

or



<script>

function getwindowsize() {

return (typeof window.innerWidth!= 'undefined') ? innerWidth :
(typeof document.body.clientWidth != 'undefined') ? document.body.clientWidth :
(typeof document.documentElement.offsetWidth != 'undefined') ? document.documentElement.offsetWidth : null;
}

</script>


Gets the actual window size.

sir pannels
09-27-2003, 01:07 PM
hey,
cheers - taking another look. in the 12XX screen and 800Xxxx it works fine its just screen sizes about the 12 one :s

Harry
09-28-2003, 09:25 AM
I tried this and it worked for me.

<?php

$sript_err=str_repeat("&middot",7)." Scripting Error ".str_repeat("&middot",7);

?>
<noscript>
<html>
<head><title>Index</title></head>
<body background="blue_fade.jpg"><br><br><br><br><br><br>
<center><font size="8" face="arial" color="red">
<b><?php echo $script_err; ?></font><br><br><br>
<center><font size="6" face="arial" color="cyan">
<b>Your web browser does not have scripting enabled.<br>
Scripting must be enabled in order to run this application.<br><br>
Contact ITCS to have scripting enabled on your workstation
</font>
<bgsound src="notify.wav"></bgsound>

</body>
</html>
</noscript>

<html>
<head><title>Index</title>

<script language="javascript">
function openSite(){
var wide=screen.width;
var high=screen.height;
var where_to;

switch(wide)
{
case 640:
switch(high)
{
case 480:
where_to='ps_page_one_640.php';
}
break;
case 800:
switch(high)
{
case 600:
where_to='ps_page_one_800.php';
}
break;
case 1024:
switch(high)
{
case 768:
where_to='ps_page_one_1024.php';
}
break;
case 1152:
switch(high)
{
case 864:
where_to='ps_page_one_1152.php';
}
break;
case 1280:
switch(high)
{
case 1024:
where_to='ps_page_one_1280.php';
}
break;
default:
where_to='ps_page_one_1024.php';
}

var mainwin = window.open(where_to,"mainwin", "");
window.opener='England_swings';
window.close();
}
</script>

</head>

<body onload="openSite()">

</body>
</html>

javasam
09-30-2003, 12:55 AM
I made a flash movie 750 by 500 on 1024 by 768 screen resolution. I know it looks big on 800 by 600 resolution. If I use above script. Does my movie looks the same as it would appear on 1024 by 768 screen resolution?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum