Js object-oriented learning note (cookie used with get parameters of url), Learning note cookie
1. Use of cookies
<Script src = "http://code.jquery.com/jquery-1.9.0.min.js"> </script> <script src = ". /jquery. cookie. js "> </script> <script> // The default cookie scope for this setting and removal is $. cookie ("favorite-city", "London"); $. removeCookie ("favorite-city"); // sets cookie $. cookie ("favorite-city", "London", {path: "/", domain: "test.com"}); $. removeCookie ("favorite-city", {path: "/", domain: "test.com"}); // get the cookie variable $. cookie ("favorite-city"); // set the expiration date var Date = new date (); var m = 6; // minutesdate. setTime (date. getTime () + (m * 60*1000); $. cookie (key, value, {expires: date}); // or $. cookie ("favorite-city", "", {expires: new Date (2013, 10, 29, 11, 00, 00), secure: true}); </script>
2. get the get parameter of the url address
<Script>/*** get the get parameter on the url */function getUrlParameter (sParam) {var sPageURL = window. location. search. substring (1); var sURLVariables = sPageURL. split ('&'); for (var I = 0; I <sURLVariables. length; I ++) {var sParameterName = sURLVariables [I]. split ('='); if (sParameterName [0] = sParam) {return sParameterName [1] ;}} /* example */var tech = getUrlParameter ('techn'); var blog = getUrlParameter ('blog '); alert (tech); alert (blog); </script>