What I'm trying to do is depending on the page title, an image in the body would change. For example, if the page title is "We Love Apples," the image in the body would be an apple. If the title contains another fruit, it would show that other fruit. If the page title doesn't contain any word that the script is looking for, then there would be a default image in the body.
I did find this script from http://www.codingforums.com/archive/index.php/t-218600.html but I can't seem to make it work.
Anyone has any tips or pointers? Appreciate the help!
<!doctype html>
<html>
<title>2image</title>
<head>
</head>
<body>
<div><img src="" alt="anImageDesc" name="myimage" width="50px" height="50px" id="someImage" />
</div>
<script type="text/javascript">
var imgs = [
"http://www.domain.com/images/image_255 Company_Name.jpg",
"http://www.domain.com/images/image_256 Company_Name.jpg",
"http://www.domain.com/images/image_257 Company_Name.jpg" //no comma after last image
];
var el = document.getElementById("someImage");
var title = document.title;
for (var i=0;i<imgs.length;i++){
if (imgs[i].indexOf(title) != -1) {
el.src = imgs[i];
break;
} else {el.src = "image_256.gif"} //a default image incase nothing is found
}
</script>
</body>
</html>