chechu
11-27-2009, 01:36 PM
Hey all,
I am looking for a script that loads a different image every time the page gets loaded.
I found this script by Twey on this forum:
<script type="text/javascript">
window.onload = function() {
var randomImages = [
"folder1/image1.png",
"folder2/image2.jpg",
"folder2/image3.gif",
"folder3/image4.tga"
];
document.images['random_image'].src = randomImages[Math.floor(Math.random() * randomImages.length)];
};
</script>
</head>
<body>
<img id="random_image" src="defaultImage.png">I had to answer this purely because it's 0547, my vision's getting a little blurry, and I read the "random" in the title as "condom."
Couldn't help leaving what you wrote Twey, but anyway.
Tricky thing is the following, which can be seen here: http://www.portretkunst.be
1/ I would like to have the three images be randomly replaced by others onload
2/ there is already a JavaScript code in the head (for the multiple select boxes), maybe therefore Twey's code doesn't work here:
<script type="text/javascript">
(function(){
function loader(){
initListGroup('chainedmenu', document.listmenu0.firstlevel, document.listmenu0.secondlevel, document.listmenu0.thirdlevel, 'savestate');
}
if (window.addEventListener)
window.addEventListener('load', loader, false);
else if (window.attachEvent)
window.attachEvent('onload', loader);
})();
</script>
I would also like to have every image linked to a page within the same site. Any suggestions, please ?
I am looking for a script that loads a different image every time the page gets loaded.
I found this script by Twey on this forum:
<script type="text/javascript">
window.onload = function() {
var randomImages = [
"folder1/image1.png",
"folder2/image2.jpg",
"folder2/image3.gif",
"folder3/image4.tga"
];
document.images['random_image'].src = randomImages[Math.floor(Math.random() * randomImages.length)];
};
</script>
</head>
<body>
<img id="random_image" src="defaultImage.png">I had to answer this purely because it's 0547, my vision's getting a little blurry, and I read the "random" in the title as "condom."
Couldn't help leaving what you wrote Twey, but anyway.
Tricky thing is the following, which can be seen here: http://www.portretkunst.be
1/ I would like to have the three images be randomly replaced by others onload
2/ there is already a JavaScript code in the head (for the multiple select boxes), maybe therefore Twey's code doesn't work here:
<script type="text/javascript">
(function(){
function loader(){
initListGroup('chainedmenu', document.listmenu0.firstlevel, document.listmenu0.secondlevel, document.listmenu0.thirdlevel, 'savestate');
}
if (window.addEventListener)
window.addEventListener('load', loader, false);
else if (window.attachEvent)
window.attachEvent('onload', loader);
})();
</script>
I would also like to have every image linked to a page within the same site. Any suggestions, please ?