Skip to content

Instantly share code, notes, and snippets.

@zela
Created March 18, 2011 12:30
Show Gist options
  • Save zela/875981 to your computer and use it in GitHub Desktop.
Save zela/875981 to your computer and use it in GitHub Desktop.
common deal with cookies
// From Flanagan's book
// Recieve all document cookies
var allcookies = document.cookie;
// Search desired cookie
var pos = allcookies.indexOf("version=");
// If founded, extract it and use it's value
if (pos != -1) {
var start = pos + 8;
var end = allcookies.indexOf(";". start); // Start of value
if (end == -1) end = allcookies.length; // End of value
var value = allcookies.substring(start, end); // Extract it
value = decodeURIComponent(value); // Decode it
// Deal with it!
if (value != document.lastModified)
alert("Document was modified since your last visit!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment