Js object-oriented learning note (cookie used with get parameters of url), Learning note cookie

Source: Internet
Author: User

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>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.