Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Mobile Drop Down Menu Preparation

Neeta Ghosh
Neeta Ghosh
839 Points

Can I put an expiration date and time on an a href element?

Is it possible to imply an expiration date and time on a link that is sent via email or deactivates the link once the documents are downloaded and moves the link to a different folder using jquery?

2 Answers

Christoph Paterok
Christoph Paterok
7,676 Points

Hi Neeta,

yes, it is possible. Perhaps this is a solution you can use:

Add a parameter to the url You can add a paramaeter with the expiration date to the url. Perhaps like this: http://example.com?expired=1421399306

Getting the parameters with jQuery The window-object has the parameters of the url here:

window.location.search.substring(1)

So now you can check is the parameter there? And in the next step you can check if the timestamp is valid.

I think this is not the securest way, but it's a base were you ca build on.

IMPORTANT

Just a info: Be sure you use the canonical-tag in your website. For a search engine a url with a parameter is a new document. So there is the risk of duplicate content. When you use the canonical-tag you can say, that it is not a new document. JFYI

Nathan Wakefield
Nathan Wakefield
7,065 Points

Another possibility is the use of cookies. These are stored in the visitor's browser, and can contain almost any data you want. As an example, your expiration date.

http://www.w3schools.com/js/js_cookies.asp

I hope this helps!