Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder Crake's Avatar
    Join Date
    Dec 2004
    Location
    Loose, Maidstone, KENT
    Posts
    577
    Thanks
    0
    Thanked 3 Times in 3 Posts

    change background via javascript

    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!
    SteveO

  • #2
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    525
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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.
    Single Paradox
    My Site (Under construction)

    Not too bad for a 15 year old

  • #4
    New Coder
    Join Date
    May 2005
    Location
    Alabama
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you would like to do it more professionaly, something like this would work:
    Code:
    <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.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Quote Originally Posted by jshl_wiz
    and I believe FireFox.
    No. You should use document.getElementById. All modern browsers support it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •