...

View Full Version : Background Change depending on Browser Detection.



Notre
07-19-2007, 03:49 AM
I need a script that if a user has Firefox, Opera, Safari, or Mozilla that it will display one background image for the index page, and it will display another background if the user has Internet Explorer or Netscape. Due to HTML/Browser view incompatibility. The IE and Netscape make the background drop 7 pixels which throws off the whole page.

rnd me
07-19-2007, 04:35 AM
something like this should work.


<body onload="setBG()">
<h1>Welcome to my page</h1>

<script>
function setBG(){
document.body.style.backgroundImage=((!!document.all)?'iebg.jpg':'w3bg.jpg')
return}

</script>

</body>

Notre
07-19-2007, 09:14 PM
something like this should work.


<body onload="setBG()">
<h1>Welcome to my page</h1>

<script>
function setBG(){
document.body.style.backgroundImage=((!!document.all)?'iebg.jpg':'w3bg.jpg')
return}

</script>

</body>


That doesn't help me since I have no idea how to edit Javascript. XD

Philip M
07-20-2007, 07:31 AM
That doesn't help me since I have no idea how to edit Javascript. XD

Well, what you need to do is replace iebg.jpg with the name of the background image to be displayed if the browser is IE, and replace w3bg.jpg with the name of the background image to be displayed otherwise.

However, there is a typo in rnd me's code, and Opera is not covered:-:-

<body onload="setBG()">
<h1>Welcome to my page</h1>

<script>
function setBG(){
document.body.style.backgroundImage=((!!document.all || window.opera) ? 'w3bg.jpg : 'iebg.jpg') // delete the second ! and switch the jpgs
return
}

</script>

In English, if the browser does not support document.all (which is supported only in IE4+) or is Opera then display the background iamge w3bg.jpg. If the browser does support document.all then display the background image iebg.jpg.



</body>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum