Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screen size or browser window size??

Status
Not open for further replies.

bewin99

Programmer
Sep 25, 2008
15
GB
The following code apparently measures the screen size and not the browser window size, which is the wrong way to go about testing screen suitability for a website.

I have designed three sites with the following dimensions as a basis: 640x480, 800x600 and 1024x768 and was sure that screen size was right ~is it?

var width = screen.width;var res =(((!(640-width))*1)+((!(800-width))*2)+((!(1024-width))*3)+((!(1152-width))*4)+((!(1280-width))*5)+((!(1600-width))*6));
if(!(res)) res = 1;if (res=='1') {window.location='if (res=='2') {window.location='if (res=='3') {window.location='if (res!='1' && res!='2' && res!='3') PopupCenter ('}
 
you don't need to do any calculations to determine the screen width...use "screen.width" to determine it and place your actions within a switch:

Code:
<script language="javascript" type="text/javascript">
switch (screen.width) {
	case 640:
		// do 640 x 480 task
		break;
	case 800:
		// do 800 x 600 task
		break;
	case 1024:
		// do 1024 x 768 task
		break;
	default:
		// do default task (none of the above)
		break;
}
</script>


--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Also, think whether you really need to use JavaScript to do this, or whether coding a fluid layout using CSS alone would be a better (and nicer) option.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top