faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 16 people (38%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

detect browser screen size to choose style sheet

Apr 8th, 2008 18:21
ha mo, Abolfazl Shirazi, AJ BJ, Abolfazl Shirazi


Abolfazl Shirazi :
Good question friend and the answer is really easy and nice. The 
function below detect the screensize and change the color of the div 
layer on the page.
<html>
	<head>
		<title>Untitled Page</title>
	<script language="javascript">
	function SetColor() {
		if (screen.width == 1024 && screen.height == 768) {
			MyDiv.style.color = "green"
			return true
		}
		if (screen.width == 1024 && screen.height == 768) {
			MyDiv.style.color = "blue"
			return true
		}
		MyDiv.style.color = "red"
		return false
	}
	</script>
	</head>
	<body bgcolor="#ffffff" onload="SetColor()">
	<div id="MyDiv" style="font:bold 12pt arial">
	The color of this layer becomes blue if the screen size is 
800x600 and it becomes green if the screen size is 1024x768 and 
becomes red if the screen size is not 1024x768 or 800x600</div>
	</body>
</html>
Enjoy It Friend !!!
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com