This code works perfectly fine by itself but as soon as I embed it into a website it no longer loads an image on page load. Why? How can it be improved?
My guess is the susceptible windowon.load
. Maybe it can be substituted?
//$(document).ready(function(){choosePic;}
//alert(window.onload);
//https://stackoverflow.com/questions/2810825/javascript-event-window-onload-not-triggered;
window.onload = choosePic;
var onloadd = window.onload;
var myPix = new Array(
"https://m.box.com/file/903146245504/https%3A%2F%2Fapp.box.com%2Fs%2Fj7i88s6jb4yyk4wmiti4tol8ejoikdhl/preview/preview.png",
"https://m.box.com/file/1055524661946/https%3A%2F%2Fapp.box.com%2Fs%2Fj7i88s6jb4yyk4wmiti4tol8ejoikdhl/preview/preview.png",
"https://m.box.com/file/896387464705/https%3A%2F%2Fapp.box.com%2Fs%2Fj7i88s6jb4yyk4wmiti4tol8ejoikdhl/preview/preview.png"
);
function choosePic() {
var randomNum = Math.floor(Math.random() * myPix.length);
document.getElementById("myPicture").src = myPix[randomNum];
('#myPicture').html(` ${myPicture} `);
('#today').html(` ${onloadd} `);
}
<button id=onloadd></button>
<button id="myrdpbtn" style="background:transparent; border:transparent;" onclick="choosePic()">RandomPicture</button>
<button id=onloadd></button><br>
<img src="https://ry3yr.github.io/OSTR/release/0mine/documents/art/empty.png" width=1000 id="myPicture"><br><br>
Comments
Post a Comment