JS implementation of page A to the page B to pass the parameters of the method _javascript skills

Source: Internet
Author: User

This article for everyone to share the JS implementation page A to the page B of the specific methods for reference, the specific content as follows

method One: Use the HTML5 localized storage (localstorage) component (local maximum storage of 5M data) Localstorage is the local persistent storage data, is the cookie optimization

method Two: use cookies to store data in the customer's browser (maximum storage 2M data)

method Three: use URL arguments (save the data to be passed as a stored variable, and then pass to the URL) method as follows;

A.html

var app = {};
App.list = ' 123 '
app.test = ' 1 ';

Window.location.href = "B.html?name=" +APP;

How the argument is the object must first convert the character json.stringify (app), and then convert the word in the B page to the object

B.html

Receive parameters passed by URL

function Getrequest () {  
  var url = location.search;//Get URL "?" Character string  
  var therequest = new Object ();  
  if (Url.indexof ("?")!=-1) {  
   var str = url.substr (1);  
   STRs = Str.split ("&");  
   for (var i = 0; i < strs.length i + +) {  
     Therequest[strs[i].split ("=") [0]]=unescape (Strs[i].split ("=") [1]);  
   }  
  }  
  return therequest;  
}  
Console.log (Json.parse (Getrequest (). Name). List)

Each browser has a limit on the length of the URL:

1. IE browser to the length of the URL is limited to 2048 bytes (its own test for up to 2047 bytes).

2.360 Speed browser limits the length of the URL to 2118 bytes.

3. Firefox (Browser) limits the length of the URL to 65536 bytes.

4. Safari (Browser) limits the length of the URL to 80000 bytes.

5. Opera (Browser) limits the length of the URL to 190000 bytes.

6. Google (chrome) limits the length of the URL to 8182 bytes.

Here, I have only tested IE browser and 360 Speed browser, other browsers from the online data.

In addition to remind you, in the URL, a Chinese character through different encoding method size is not the same.

The above is JS to implement a page for another page to pass the parameters of the method, I hope that you learn JavaScript programming help.

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.