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?

5 of 10 people (50%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

Changing background image depending on screen res

Apr 7th, 2008 23:01
ha mo, Colin Fraser, kris Nelson,


Use these:
in Netscape:
window.innerWidth - Specifies the horizontal dimension, in pixels, of
the window's content area. 
in IE
screen.width - Specifies the horizontal resolution of the screen, in
pixels. 
so the script in the head would be : 
<script type="text/javascript">
//determin browser name
bname=navigator.appName
  if (bname.indexOf("Netscape")!=-1) {
     scrwidth= window.innerWidth;
     }
  if (bname.indexOf("Microsoft")!=-1) {
     scrwidth=screen.width
     }
}
switch (scrwidth) {
	case 600 :
		document.write("<body background='600.jpg'>")
		break;
	case 800 :
		document.write("<body background='800.jpg'>")
		break;
	default:
		document.write("<body background='1000.jpg'>")
}
This code replaces the normal prewritten and fixed body tag.
This has some risk attached to it, mainly because there are so many
screens out there with so many different resolutions. You may be asking
for more trouble than you expect.
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