Body Color change

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shoeyoz
    New Member
    • Feb 2008
    • 4

    Body Color change

    Hi Everybody,

    m suyoz,

    i have made body color change onmouse click in every webpages but what i want is dat when i choose for eg blue body color .after dat when i click on link to other page i want same color which i have chosen before[blue] .. so please help me..
  • shoeyoz
    New Member
    • Feb 2008
    • 4

    #2
    Body color change

    i have made body color change onmouse click ..but i want is to make default color or if one goes to other page dat page must open with same body color dat i have chosen..can anyone help me..please

    script for color change

    [CODE=javascript]var backImage = new Array();

    backImage[0] = "images/bg.jpg";
    backImage[1] = "images/background.jpg" ;
    backImage[2] = "images/dark.jpg";
    backImage[3] = "images/white";
    backImage[4] = "images/lightblue.jpg";
    backImage[5] = "images/lightpink.jpg";
    backImage[6] = "images/grey.jpg";
    backImage[7] = "images/1.jpg";
    backImage[8] = "images/2.jpg";
    backImage[9] = "images/eeeeee.jpg";
    backImage[10] = "images/3.jpg";
    backImage[11] = "images/4.jpg";
    backImage[12] = "images/5.jpg";
    backImage[13] = "images/6.jpg";
    backImage[14] = "images/7.jpg";
    backImage[15] = "images/8.jpg";
    backImage[16] = "images/9.jpg";
    backImage[17] = "images/10.jpg";
    backImage[18] = "images/11.jpg";
    backImage[19] = "images/12.jpg";
    backImage[20] = "images/13.jpg";
    backImage[21] = "images/14.jpg";
    backImage[22] = "images/15.jpg";
    backImage[23] = "images/16.jpg";
    backImage[24] = "images/17.jpg";
    backImage[25] = "images/18.jpg";
    backImage[26] = "";

    function changeBGImage(w hichImage){
    if (document.body) {
    document.body.b ackground = backImage[whichImage];

    }
    }[/CODE]
    Last edited by gits; Feb 8 '08, 08:31 AM. Reason: added code tags

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      If your not using any server side language, like PHP or ASP, then you need to have two functions:

      1 function will put the values in the URL like

      somepage.html?b g=2

      2nd function will retrive it that value.

      Here's the function that retrives the value of a parameter and returns an empty string if it is not found:



      Second, you need to pass this value to each of your pages.

      I would have a changePage() function and evey link in your page will need to use this function to change the page.

      Code:
       
      // put this at the top of your script
      var bgNum = 0; // 0 or any other one you want as default. 
       
       
      function changePage(URL)
      {
      	window.location = URL + "&bgNum=" + bgNum;
      }
       
       
      // modify your changeBGImage function to
      function changeBGImage(whichImage)
      {
      if (document.body){
      document.body.background = backImage[whichImage];
       
      bgNum = whichImage; // store it in bgNum Variable. 
       
      }
       
      // to load the bg on the next page you use that gup in the link i gave you
       
      document.body.background = gup(bgNum);
       
      // or call that with the body onload function like so: 
      
      <body onLoad="document.body.background=gub(bgNum);">
      Hope that helps you to be on your way... post any questions.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Merged thread on the same topic. Please keep all posts relating to one specific problem in one thread. Thanks!

        Comment

        • shoeyoz
          New Member
          • Feb 2008
          • 4

          #5
          Originally posted by dlite922
          If your not using any server side language, like PHP or ASP, then you need to have two functions:

          1 function will put the values in the URL like

          somepage.html?b g=2

          2nd function will retrive it that value.

          Here's the function that retrives the value of a parameter and returns an empty string if it is not found:



          Second, you need to pass this value to each of your pages.

          I would have a changePage() function and evey link in your page will need to use this function to change the page.

          Code:
           
          // put this at the top of your script
          var bgNum = 0; // 0 or any other one you want as default. 
           
           
          function changePage(URL)
          {
          	window.location = URL + "&bgNum=" + bgNum;
          }
           
           
          // modify your changeBGImage function to
          function changeBGImage(whichImage)
          {
          if (document.body){
          document.body.background = backImage[whichImage];
           
          bgNum = whichImage; // store it in bgNum Variable. 
           
          }
           
          // to load the bg on the next page you use that gup in the link i gave you
           
          document.body.background = gup(bgNum);
           
          // or call that with the body onload function like so: 
          
          <body onLoad="document.body.background=gub(bgNum);">
          Hope that helps you to be on your way... post any questions.


          //Sorry it didn't work.. Well thanks for ur code once again thanks for showing some way now i can try it

          bye

          suyoz..

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by shoeyoz
            //Sorry it didn't work.. Well thanks for ur code once again thanks for showing some way now i can try it
            What didn't work? Give more details.

            Comment

            • shoeyoz
              New Member
              • Feb 2008
              • 4

              #7
              Originally posted by acoder
              What didn't work? Give more details.
              u can check in this url http://www.dobaltechno lgies.com
              and i have paste the script above..
              so please help me..

              i want if bodycolor change once than when u'll visit other page bodycolor of visited page must not be changed it should be remain same .

              thanks

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Use cookies. When you set the body colour, set a cookie. On the next page, retrieve the cookie and set the body colour based on that. If you don't know how to get/set cookies, see this tutorial.

                Comment

                • Zorba CafeSpeak
                  New Member
                  • Feb 2008
                  • 1

                  #9
                  Hi ... Could you tell me how to do the same thing but within a table in a html page... When I tried using document.body.b ackground, the effect comes up in the page background not the table background...

                  Thanks for your help

                  Zorba

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Originally posted by Zorba CafeSpeak
                    Hi ... Could you tell me how to do the same thing but within a table in a html page... When I tried using document.body.b ackground, the effect comes up in the page background not the table background...

                    Thanks for your help

                    Zorba
                    Set the table's style.backgroun dColor property.

                    Comment

                    Working...