Utility Mill

Auto_Expiring_HTML

Forget to remove "New .." descriptions from your website? Let Javascript do it for you


Output


Instructions / Discussion

Tired of seeing "New" written around old content on your websites? Want to display something only for a short time?

Well, now you can make certain HTML pieces disappear after a chosen number of days.

Instructions

Paste whatever HTML you want to expire/disappear into the "HTML Snippet" field. Set the number of days you want it to expire in and run the utility.

Paste the output into the desired location in your website.

How it Works

This will wrap a div tag around whatever HTML you enter, and put some javascript under it to hide that div if the current date is greater than your set expiration.

Want to use this in a WordPress post?

Then things get a little tricky :-) WordPress doesn't allow javascript in posts. So we just have to import a javascript file to get around it.

Take the javascript part of the output (part in between the script tags but not including the script tags) and put it into a file say: expire.js. Then upload that file to your website.

Take the HTML part of the output and put it into your blog post somewhere. Then put this line into your blog post under it:

<script type="text/javascript" src="URL TO expire.js" />

Here's an example WordPress post using this technique. In this hypothetical example, your post made it to the front page of reddit, so you want to welcome the visitors. But you know reddit is a fickle lover and will have forgotten about you within 2 days, so you have set the "welcome redditors" message to dissapear after that:

<div id="utilitymill_28557"> <p>Welcome Redditors!</p> </div>

<script type="text/javascript" src="/wp-content/uploads/2007/10/expire.js" />

Brilliant post ...

Developer Notes

Javascript's setFullYear expects month-1, it's not a bug.

Compress option just removes new lines, needs to remove spaces, etc too.

I haven't tested this beyond Firefox, please let me know how it goes, or just fix this utility.

Can you think of a less intrusive way to edit a users HTML?

Utility Mill is another wonderful Blended Technologies project.

copyright, owned and operated by Blended Technologies LLC.

Powered by Python and the ineffable Web.py