How to change body background with image by javascript?
html body background change
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and shareā ātheir programming āknowledge and build their careers.
Put the java script between head tag.Create a folder āimagesā and keep all the images in that folder
<html>
<head>
<title>Change body background</title>
<script type="text/javascript">
var picPaths = [āimages/pic1.jpgā,āimages/pic2.jpgā,āimages/pic3.jpgā,āimages/pic4.jpgā];
var oPics = [];
for(i=0; i < picPaths.length; i++){
oPics[i] = new Image();
oPics[i].src = picPaths[i];
}
curPic = Math.floor(Math.random()*oPics.length);
window.onload=function(){
document.getElementById(āimgRotatorā).src = oPics[curPic].src;
}
</script>
</head>
<body>
<img id="imgRotator" src="" alt="" height="470" width="600"/>
</body>
</html>