I'm working on a site and I want to give the users option to change the background image.
Of course client-side. My default background-image is put in CSS file.
body {
background-image: url(images/back.jpg);
overflow: visible;
width: 1260px;
}
I've tried to make some javascript trigering the change
var img = "images/backy.jpg"
function cng(){
if(document.body){
document.getElementsByTagName("BODY").style.background = img;
}
}
It won't work
var img = "images/backy.jpg"
function cng(){
if(document.body){
document.body.background = img;
}
}
Also won't work
The HTML is:
<p class="cng" onclick="cng()"><b>Change background</b></p>
document.write isn't solution. Another important thing is that the image have to be user specified(the user is selecting image from his computer like in uploading file).