|
When you add something to your site or modify something, you usually place a icon next to it so that visitors can easily find it. The idea is to display the icon for a fixed period of time and then remove it. However, if you are constantly modifying your site or if you have a large number of pages, then keeping track of all the new icons becomes very difficult. Using JavaScript, it is possible to program your HTML to display the new icon only for a certain period of time. You write a JavaScript function which compares the current date with the expiry date and inserts the new icon only if the current date has not exceded the expiry date. Here is the code : <SCRIPT LANGUAGE="JavaScript"> <!-- Hide code from non-js browsers function newItem(expiryDate) { exp = new Date(expiryDate); cur = new Date(); if (cur.getTime() < exp.getTime()) document.write("<IMG SRC=\"new.gif\" WIDTH=31 HEIGHT=12 BORDER=0>" ALT=\"new\"); } // end hiding --> </SCRIPT>Usually, functions like this are defined between the <HEAD> and </HEAD> |