vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How do I change the .body background color with Javascript? (https://vborg.vbsupport.ru/showthread.php?t=200086)

Triky 12-29-2008 02:02 PM

How do I change the .body background color with Javascript?
 
As per title. I would like to add an option to let users change the style's .body background color in their usercp. And it should be saved in their options, so they see that color until they change it again.

UKBusinessLive 12-29-2008 02:20 PM

Hi,

i've been looking at something like this myself, here is a very basic example

1st you need to save this code as a Javascript so copy it to your notepad and save it as "Backcolor.js"

Code:

function change_it() {
       
  if (document.getElementById && document.createTextNode) {
         
    var new_color = "";
    var color_sel = document.getElementById("change_bg").value;
        color_sel *= 1;
   
        switch (color_sel) {
      case 0 : window.alert("Please select a color."); return false;
          case 1 : new_color = "#FFFF00"; break;
      case 2 : new_color = "#3333FF"; break;
          case 3 : new_color = "#009900"; break;
        }
   
        document.body.style.backgroundColor= new_color;
    return false;
       
  }
 
}

then you upload the backcolor.js file to same directory as the Web page on which you will use the script (ideally your Forum Root)

Then enter the code below, between the <body> and </body> tags where you want the select box and button to appear, ideally in the footer or header templates

Code:

<form action="#" onsubmit="return change_it();">
<select name="change_bg" id="change_bg">
<option selected="selected" value="0">Select Background</option>
<option value="1">Yellow</option>
<option value="2">Blue</option>
<option value="3">Green</option>
</select>
<input type="submit" value="Change Color" />
</form>
<script type="text/javascript" src="backcolor.js"></script>

What that will do is give your users a dropdown box with a Change Color button ( for the english spelling please change the above code here <input type="submit" value="Change Color" />

i've done this very basic, but you can change the colors in the backcolor.js file just change the case 1, 2 and 3 options with a new hex color #FFFFFF

You can get a nice selection of hexcolors here http://www.december.com/html/spec/colorsafe.html

This is what you get, Mind you it won't work well on my forum as its fluid, but it'll work well with fixed forums

https://vborg.vbsupport.ru/external/2008/12/4.png
https://vborg.vbsupport.ru/external/2008/12/5.png
https://vborg.vbsupport.ru/external/2008/12/6.png

Remember you can change these colors, I've just done 3 as an example, But you can add as many as you want and with millions of combinations by using a color Hex chart.

Have Fun

;)


To see the new template edit in the mods forum https://vborg.vbsupport.ru/showthread.php?t=200096


All times are GMT. The time now is 03:28 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00907 seconds
  • Memory Usage 1,717KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete