Forum Moderators: open
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Welcome To My Website</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="Javascript" type="text/javascript">
<!-- To be placed in an external .js file
if (document.images) {
backOvr = new Image;backOvr.src = "images/backovr.gif"
backOut = new Image;backOut.src = "images/backout.gif"
nextOvr = new Image;nextOvr.src = "images/nextovr.gif"
nextOut = new Image;nextOut.src = "images/nextout.gif"
}
else {
backOvr = "";backOut = "";document.button1 = ""
nextOvr = "";nextOut = "";document.button2 = ""
}
function imgOver(thisImg) {
document[thisImg].src = "images/" + thisImg + "ovr.gif"
}
function imgOut(thisImg) {
document[thisImg].src = "images/" + thisImg + "out.gif"
}
function activeImages() {
document.getElementById("button2").onmouseover="imgOver('next');window.status='Next Page';return true"
document.getElementById("button2").onmouseout="imgOut('next');window.status='';return true"
}
document.onLoad = activeImages;
// End external .js file -->
</script>
</head>
<body>
<a href="example1.com" onmouseover="imgOver('back');window.status='Previous Page';return true"
onmouseout="imgOut('back');window.status='';return true">
<img src="images/backout.gif" width="129" height="29" border="0" name="back" id="button1" alt="Previous Page" /></a>
<br>
<br>
<a href="example2.com">
<img src="images/nextout.gif" width="129" height="29" border="0" name="next" id="button2" alt="Next Page" /></a>
</body>
</html>
I also tried...
window.onLoad = function activeImages{rest of the function}
window.onload (as per Fotiman). Case sensitivity.
-----------
Drop all the uses of the name attribute for images.
Switch names to ids.
Use Fotiman's code.
-----------
Don't use eval.
[edited by: Bernard_Marx at 12:10 am (utc) on July 28, 2007]
function imgOver(thisImg) {document[thisImg].src = "images/" + thisImg + "ovr.gif"}
function imgOut(thisImg) {document[thisImg].src = "images/" + thisImg + "out.gif"}
/* Previously used = eval(thisImg + "Ovr.src") and = eval(thisImg + "Out.src") as per Drag_Racer. Surely using the preload images would reduce any delay and calls to the server*/
function activeImages() {
document.getElementById("button1").onmouseover=function() {imgOver('back');window.status='Previous Page';return true;};
document.getElementById("button1").onmouseout=function() {imgOut('back');window.status='';return true;};
document.getElementById("button2").onmouseover=function() {imgOver('next');window.status='Next Page';return true;};
document.getElementById("button2").onmouseout=function() {imgOut('next');window.status='';return true;};
} /*Thanks to Fotiman for this code but it was missing the return true parts of each window.status section and the last right curly-bracket to end the function.*/
window.onload = activeImages; // I previously used window.onLoad, thank you Bernard Marx for pointing this out.
// End
[edited by: steve1802uk at 11:41 pm (utc) on July 28, 2007]