I'm testing a theory before using it on a production site.
I want to be able to swap images, based on the current url...so I'm thinking document.referrer.indexOf will be the easiest way to handle this.
I've come up with the following page, but it doesn't work as I expect it to work. I want it to display the homeRPG.gif image if the url contains "test" (ie or otherwise I want it to display the homeDefault.gif image. I'm testing this locally, from it should be displaying the homeDefault.gif image, but it's not. In fact I can change the rpg in ...indexOf("rpg") to anything and it still just displays the homeRPG.gif image. Can anyone show me where I'm going wrong here? Thanks!
I want to be able to swap images, based on the current url...so I'm thinking document.referrer.indexOf will be the easiest way to handle this.
I've come up with the following page, but it doesn't work as I expect it to work. I want it to display the homeRPG.gif image if the url contains "test" (ie or otherwise I want it to display the homeDefault.gif image. I'm testing this locally, from it should be displaying the homeDefault.gif image, but it's not. In fact I can change the rpg in ...indexOf("rpg") to anything and it still just displays the homeRPG.gif image. Can anyone show me where I'm going wrong here? Thanks!
Code:
<html>
<script>
function chkURL()
{
if(document.referrer.indexOf("rpg") == -1)
{
document.getElementById('home').src = "testImgs/homeRPG.gif";
}
}
</script>
<body onload="chkURL()">
<img src="testImgs/homeDefault.gif" name="home" id="home" />
</body>
</html>