New Revised CSS Library Forums Web Tools
FAQs Awards Usage Terms Contact
Categories
Other Sections
Sweet Ads
Compatibility
Bookmark online:

FF1+ IE5+ Opr7+

Frequency Cap Content

Author: Dynamic Drive

Note: Updated March 29th, 05'. Fixed bug that caused set duration to be incorrect.

Description: Want to display content that only gets shown once every x hours? With this unique script you can do just that! By using JavaScript cookies and CSS ("display" property), this script lets you cap the display frequency of any content(s) on the page to once every x hours. Each content can have its own frequency cap, and setting up the script is as easy as specifying the IDs of the contents inside the script.

Frequency capping is a great way to maximize the impact of a content, to avoid visual "burnout." Use it on content ads, special announcements etc.

Demo:

Below div shown once every hour:
 
Some div
Below image shown once every 3 hours:


Directions: Developer's View

Step 1: Insert the below script into the HEAD section of your page:

Select All

An array inside the script lets you input the IDs of the contents to frequency cap, plus the display interval in hours.

Step 2: With the script installed, simply give the contents you want to frequency cap each with the ID as specified in the script above. For example:

<div id="myad">

//some content
//some content

</div>
<table id="mynote">

//rest of table here

</table>

As you can see, the content can be anything, whether it's a DIV, table, or even an image etc. In the above case, the DIV will be shown once every hour, and the TABLE, once every 3 hours.

Useful tip: To reset the cookie for a specific content so it gets shown again, simply change the time interval for it inside array capcontent[] so it's different from the current interval (for example, from the current 1 hour to 2 hour). The script will reset the cookie whenever it detects a change in time interval from the previous for a content. This is useful for debugging/ testing purposes.

Cool!