window.onload = function(){
document.body.style.backgroundImage = "url('a.jpg')";
}
a.jpg is in the same forlder.
but
document.body.style.backgroundColor = "blue";
works fine!
whats going wrong?
window.onload = function(){
document.body.style.backgroundImage = "url('a.jpg')";
}
a.jpg is in the same forlder.
but
document.body.style.backgroundColor = "blue";
works fine!
whats going wrong?
try
document.body.style.background = 'url("a.jpg")';
this way you apply to the body a background style property. Similar as you would do with a CSS declaration. See http://www.w3schools.com/cssref/css3_pr_background.asp
Or, more similar to your code
document.body.style.backgroundImage = "url(a.jpg)";
without the single quotes. See http://www.w3schools.com/cssref/pr_background-image.asp
If still doesn't work then it is the path to the image that's wrong.
window.onload = function(){
document.body.style.backgroundImage = "url(a.jpg)";
}
fiddle:Demo