How to use the code session document.querySelector
to change / change the background image of a page <body>...</body>
Ex:
var imagem_lista = [
"http://static.gamespot.com/uploads/original/1179/11799911/2324138-warface11.jpg",
"http://glasshome.tv/wp-content/uploads/2013/10/Warface_Screenshot019_Climb.jpg",
"http://hq.warface.com/updates/endless-skies/img/WF_ES_019.jpg",
"http://lodik.ru/uploads/posts/2015-02/1423304948_warface-3.jpg",
"http://hq.warface.com/updates/siberia/img/wf-update-coldpeak-03.jpg",
"http://vignette1.wikia.nocookie.net/warface/images/4/43/Warface_WeapCustom_Combat_201.jpg/revision/latest?cb=20130301001625"
];
window.onload=function(){
var url_pagina = window.location.href;
if(!url_pagina.indexOf('/p/')){
var numero_aleatorio = random_number(0, imagem_lista.lenght);
mudar_imagem(imagem_lista[numero_aleatorio]);
}
}
function random_number(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function mudar_imagem(image){
// usar este
document.querySelector('body').style.background-image=image;
// ou este
$('body').css('background-image', 'url(' + image + ')');
}
And one of the error is as follows:
Uncaught ReferenceError: Invalid left-hand side in assignment
Uncaught ReferenceError: imagem_lista is not defined
at :2:7
at Object.InjectedScript._evaluateOn (:905:140)
at Object.InjectedScript._evaluateAndWrap (:838:34)
at Object.InjectedScript.evaluate (:694:21)
NOTE: The file containing the script is hosted on:
In the line: indexOf
I want to identify when a user accesses my blog to change the background of the image according to a defined theme.
Ex: The blog home is set to one of these images in imagem_lista
.
( link )
Now for example on the survival mode page of the game quoted there, the theme should soon change the background as well. ( link )