Jump and transmit values between HTML pages (JS code)

Source: Internet
Author: User

here's how to jump :Method One: window.location.href = "b.html"; method two (return to the previous page, this should not be counted, first put here):Window.history.back ( -1);Method Three: Self.location = "b.html"; method four: Top.location = "b.html"; thinking about the question: first, Why give window.location and window.location.href the same value, can jump? Thinking:Location is Location.href's simplicity, whether it's an interview or a value. From the function, location and so on Location.href;But from this theory, location is an image, and Location.href is one of its own. This weird line is supposed to be compatible.second, when assigning a value to a location, if the page is not in the same directory, you need to write the full URL. For example: The current location.href ishttps://www.google.com/, if you want to jump to https://www.baidu.com/, you cannot just www.baidu.com, you must write the URL complete. Pass ValueThe method is as follows: Method one: url parameter (? The following parameters) (where to go to the net pen question, the URL after the argument to resolve to the object) Window.location.href = "Https://www.google.com/search?Q=hello&oq=hello "function parseURL (URL) {var url = url.split ("? ")    [1];    var para = url.split ("&");    var len = para.length;    var res = {};    var arr = [];        for (Var i=0;i<len;i++) {arr = para.split ("=");    Res[arr[0]] = arr[1]; } return res; Method Two: The cookie passes the parameterfunction Setcookie (cname,cvalue,exdays) {var d = new Date ();D.settime (D.gettime () + (exdays*24*60*60*1000));var expires = "expires=" + d.toutcstring ();Document.cookie = cname + "=" + Cvalue + ";" + expires;}
function GetCookie (CNAME) {var name = cname + "=";    var CA = Document.cookie.split (";");        for (Var i=0;i<ca.length;i++) {var c = ca[i];         while (C.charat (0) = = ") {c = c.substring (1);        } if (C.indexof (CNAME) = = 0) {return c.substring (name.length,c.length); }} return "";} Method Three: The Localstorage object in the Web Storage in H5
Localstorage.setitem ("LastName", "Lu"), or Localstorage.lastname = "Lu";
Localstorage.getitem ("LastName"); or localstorage.lastname;

Jump and transmit values between HTML pages (JS code)

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.