Community Central
Community Central
This Forum has been archived
Forums: Admin Central Index General Questions Random background
Wikia's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.


Are we allowed to use a random wiki background?

ForestMonthZero 08:39, May 19, 2012 (UTC)

I don't think so. Perhaps ask using Special:Contact -- Sam Wang (talk) 09:19, May 19, 2012 (UTC)
Um, I can't at all see why you wouldn't be able to. If you do file a Special:Contact and get an answer in the negative, I'd greatly appreciate your update in this thread. On the face of it, that seems to be 100% stylistic choice and 0% Wikia-wide functionality. Therefore, it hardly seems like a TOU violation. czechout    fly tardis  13:45: Sat 19 May 2012 
So would the following work?
function RandomBkgnd()
{
 var bkgndArray = new Array(); 
 bkgndArray[0] = '<!-- full URL here -->';
 bkgndArray[1] = '<!-- full URL here -->';
 bkgndArray[2] = '<!-- full URL here -->';
 ...
 bkgndArray[xyz] = '<!-- full URL here -->';

 var chosenBkgnd = Math.round(Math.random() * (bkgndArray.length - 1));

 var body = document.getElementsByTagName('body')[0];
 var selectedBkgnd = ' background-image:url('+ bkgndArray[chosenBkgnd] +');';
 body.className+= selectedBknd ;
---- OR ----
 body.setAttribute("background", bkgndArray[chosenBkgnd] );
}
addOnloadHook(RandomBkgnd);
ForestMonthZero 08:27, May 20, 2012 (UTC)

(Reset indent) This should work:

randomBack = function() {
    var opts = [];
    opts.push('url here');
    opts.push('url here');
    // ....
 
    $("body").css("background-image",'url(' + opts[Math.floor(Math.random()*opts.length)] + ')');
}
 
addOnloadHook(randomBack);

You'll still briefly see the background from your CSS at first though (due to the JS only being executed when it's done loading) - Tjcool007 (Talk) 09:59, May 20, 2012 (UTC)


Thanks, that's working (well, I kind of smushed both of our code segments together.) ForestMonthZero 09:33, May 21, 2012 (UTC)

function RandomBkgnd()
{
  var bkgndArray = new Array(); 
  bkgndArray[0] = '<!-- full URL here -->';
  bkgndArray[1] = '<!-- full URL here -->';
  bkgndArray[2] = '<!-- full URL here -->';
//...
//bkgndArray[#] = '<!-- full URL here -->';

  var chosenBkgnd = Math.floor( Math.random() * bkgndArray.length );

  $("body").css("background-image",'url(' + bkgndArray[chosenBkgnd] + ')');
}
addOnloadHook(RandomBkgnd);