...

View Full Version : change background via javascript



Crake
05-30-2005, 06:00 PM
hey i want the viewers on my site to be able to change the background anyone who knows of a javascript wich is able to do this i would be very greatfull i have tried yahoo but no results were found!

thanks again codingforums! :thumbsup:

Coastal Web
05-30-2005, 07:19 PM
Do you want to change the background color?
http://javascript.internet.com/bgeffects/background-color-changer.html

more: http://www.google.com/search?hl=en&q=javascript+change+background+color

Or is it a background image you're trying to change?
http://www.codebelly.com/javascript/backimagechange.html

more: http://www.google.com/search?hl=en&q=javascript+change+background+image


Samantha Gram
HTHs

Single Paradox
05-30-2005, 08:04 PM
<a href="javascript:void(0);" onclick="document.body.style.backgroundColor='#000000';">Change BG to black</a>


^^ Change the "#000000" to whatever color you want the background to be.

jshl_wiz
05-30-2005, 08:49 PM
If you would like to do it more professionaly, something like this would work:

<html>
<head><title></title>
<script>
<!--
function changeBG(whatcolor){
if(document.all){
document.body.style.backgroundColor = whatcolor;
}
if(document.layers){
document.body.backgroundColor = whatcolor;
}
}
//-->
</script>
</head>
<body>
<b>Like a form</b><br />
<form name="likeaform">
<input type="button" onclick="changeBG('black')" value="change to black" />
<input type="button" onclick="changeBG('blue')" value="change to blue" />
</form><br />
<b>Like a link</b><br />
<a href="#" onClick="changeBG('black');" />Change to Black</a>
<a href="#" onClick="changeBG('blue');" />Change to Blue</a>
</body>
</html>

This will work in Internet Explorer, Netscape Navigator, and I believe FireFox.

glenngv
05-31-2005, 07:11 AM
and I believe FireFox.
No. You should use document.getElementById. All modern browsers support it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum