JavaScript Change Image on Specified Date

 

Version 1 - This script will change an image on or after a specified date.

 

Version 2 - This script will change an image depending on the seasons. ("Alt" image tag displayed only for demo purposes)

 

Version 3 - This script will change an image depending on the actual date you have encoded. It will also display a default image if no dates are valid.

 

Example 1



 

Script Source

Version 1

<script type="text/javascript">
// © www.wizzardweb.co.uk
var Date = new Date();
var Today = Date.getDate();

if(Today < 16)
{
document.write('<img src="https://www.imagelocation_here" alt="Image title " width="117" height="100" />');
}
else
{
document.write('<img src="https://www.imagelocation_here" alt="image title " width="117" height="100" />');
}
</script>

 

Version 2

<script type="text/javascript">
// ©2017 www.wizzardweb.co.uk
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var total = month;

// Summer
if (total >=6 && total <= 8)
{
document.write('<img src="" alt="It is now Summer" width="117" height="100" />');
}
// Autumn
else if (total >=9 && total <= 11)
{
document.write('<img src="" alt="It is now Autumn" />');
}
// Winter
else if (total ==12 || total == 1 || total == 2)
{
document.write('<img src="" alt="It is now Winter" />');
}
// Spring
else if (total >=3 && total <= 5)
{
document.write('<img src="" alt="It is now Spring" />');
}

else
{
document.write("<b><br>Error!</b>");
}
</script>

 

Version 3

<script language="javascript">
<!-- ©2017 www.wizzardweb.co.uk
var pic='';
mytime=new Date();
mymonth=mytime.getMonth()+1;
mydate=mytime.getDate();
if (mymonth==7 && mydate==15){pic="<img src=/images/14.png width=300 height=300 alt=1>";
}
else if (mymonth==7 && mydate==17){pic="<img src=/images/19.png width=300 height=300 alt=2>";
}
else if (mymonth==7 && mydate==18){pic="<img src=/images/13.png width=300 height=300 alt=3>";
}
else {
pic="<img src=/images/default.gif width=300 height=300 alt=default>"
}
document.write(pic);
//-->
</script>

 

Please let me know if this script was helpful to you.

[rating]