Thursday 15 July 2010

button - How to save current URL to a cookie, and restore with javascript onclick -


Can someone help me create a cookie to save the user's existing URL with location.href when he Click on the button, there is another "Save Progress" button in effect, then there is another load button for the user to save this cookie,

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Script & gt; Function newDoc () {window.location.assign (location.href)} & lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input type = "button" value = "load progress" onclick = "newDoc ()" & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

>

You can create a cookie using Javascript.

You can use the following functions to make it easy. You can read, correct, delete cookies using the following functions. Make a cookie using

  / *** cookie, you can read it later, e.g. Var url = readCookie ("currenturl"); *** / function newDoc () {createCookie ("currenturl", document.URL, 1); } Function createCookie (name, value, day) {if (day) {var date = new date (); Date.setTime (date.getTime () + (Days * 24 * 60 * 60 * 1000)); End of var = "; has expired" = "+ date.toGMTString ();} Completion of other var =" "; Document.cookie = name +" = "+ value + finished +"; Path = / ";} read the function (name) {var nameEQ = name +" = "; var ca = document.cookie.split (';'); for (var i = 0; i & lt; ca.length ; I ++) {var c = ca [i]; while (c.charAt (0) == '') c = c.substring (1, c.length); if (c.indexOf (nameEQ) == 0) return c.substring (nameEQ.length, c.length);} return null;} delete the function cookie (name) {createCookie (name, "", - 1);}    

No comments:

Post a Comment