Skip to content

Instantly share code, notes, and snippets.

@pankajpatel
Created April 3, 2015 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pankajpatel/13f8da832165bee4694c to your computer and use it in GitHub Desktop.
Save pankajpatel/13f8da832165bee4694c to your computer and use it in GitHub Desktop.
Redirect the user is cookie is set....
/*
Suppose you have stored the Data at server side;
you can generate a random Hash for client side
and redirect to another URL to restore the state
with the help of that hash
let:
hash = 95deb5011a8fe1ccf6552bb5bcda2ff0
//data stored or server against this hash is
data = {name: "Time to Hack",url: "http://time2hack.com"}
form_url = http://example.com/form
retrieve_url http://example.com/form?reload={hash}
i.e.
http://example.com/form?reload=95deb5011a8fe1ccf6552bb5bcda2ff0
*/
function restoreCookie(){
$('form').each(function(i){
x = $(this).attr('name');
str = $.cookie(x);
//random validation to verify stored thing as hash
if( String(str).length == 32 ) {
window.location = 'http://example.com/form?reload='+str;
/*
window.location
= 'http://example.com/form?reload=95deb5011a8fe1ccf6552bb5bcda2ff0';
*/
}
//else do nothing
//and let the user fill the form
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment