How can I create a dynamic hyperlink that will always display the current month and year?
Where possible this is a server-side task.
Insert this where you want the link generated. If JS isn't available, you get nothing:
Code:
<script type="text/javascript">
(function( content, title )
{
var dt = new Date();
document.write( "<a href='http://www.somesite.com/site_media/u...f_" + ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec' ][ dt.getMonth() ] + "_" + dt.getFullYear() + ".pdf' title='" + title +"'>" + content + "<\/a>");
})
( "Click me", "Goes to some site" ); /* <-- Link text and link title */
</script>
This is perfect except for one thing I am trying to display reports for the previous month when adding -1 for the getMonth, and if the current month is Jan it will calculate 0 -1 = -1, and it will not display the previous month which is Dec.
Thanks
Code:
<script type="text/javascript">
(function( content, title )
{
var dt = new Date();
document.write( "<a href='http://www.somesite.com/site_media/u...f_" + ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec' ][ dt.getMonth() -1 ] + "_" + dt.getFullYear() + ".pdf' title='" + title +"'>" + content + "<\/a>");
})
( "Click me", "Goes to some site" ); /* <-- Link text and link title */
</script>