Results 1 to 3 of 3

Thread: Change background image?

  1. #1
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Change background image?

    I've been trying to create a script to change the background image of my site and store it in a cookie. This is what I have so far:

    Code:
    <script language="javascript">
    <!--
    var backImage = new Array();
    
    back[0] = "aquablack.jpg";
    back[1] = "aquablue.jpg";
    back[2] = "aquared.jpg";
    
    function changebgimage(backnum){
    if (document.body){
    document.body.background = back[backnum];
    }
    }
    function cookie(number){
    if (document.body){
    document.cookie = "background="+number+";expires=Fri, 17 Dec 2010 12:00:00 GMT";
    }
    }
    
    function bgimage(somenumber){
    if (document.body){
    changebgimage(somenumber);
    cookie(somenumber);
    }
    }
    
    function ReadCookie(cookieName) {
     var theCookie=""+document.cookie;
     var ind=theCookie.indexOf(cookieName);
     if (ind==-1 || cookieName=="") return ""; 
     var ind1=theCookie.indexOf(';',ind);
     if (ind1==-1) ind1=theCookie.length; 
     return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
    }
    
    var bg = ReadCookie(background);
    
    function initialbackground() {
    if (document.body){
    changebgimage(bg);
    }
    }
    //-->
    </script>
    Right after the <body> tag, I have this:

    Code:
    <script language="javascript">
    initialbackground();
    </script>
    I copied the ReadCookie function, so I have no idea how it works. The bgimage function changes the background and sets the cookie, but the initialbackground function doesn't seem to work. What's wrong with the script?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    What does it do/not do?
    A link to your page would help.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nevermind, I figured it out.

    I needed to put quotes.

    var bg = ReadCookie("background");

Bookmarks

Posting Permissions

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