Two page parameter JS

Source: Internet
Author: User

Scene:

Similar to popular reviews need to choose the location, and then connect to other pages, in other pages will also use this location and if previously selected location

Method One:

Use session

Sessionstorage is the session store, and the browser is off.

Localstorage is persistent storage and can be used to replace cookies with greater storage space.

Implementation method

Save: sessionstorage["Address"]= "Beijing";

Fetch: sessionstorage["Address"]

Localstorage implementation method is the same as Sessionstorage

Method Two: With the "How to obtain the url# number after the parameter"

Pass the parameters after the URL

b.html?teacher=xx&time=xxx

Back to the problem, first from a.html to b.html need a jump way, for example, in the a.html page you have a link:

<a href="b.html" id="toPageB">跳转到b页面</a>

The rest is good, get the parameters you need, then modify the page URL:

var dataFromLi=[$("#Teachername").text(),$("#Credit_hour").text()];$("#toPageB").attr("href","b.html?data="+dataFromLi);

The URL is then parsed on the b.html page to get the parameters.

How to get parameters based on URLs:

Window.location.search will return all address bars from "?" The starting string. Getting a parameter value can pass regular, here is a simple function to get the parameter:

function getURLParameter(name) {    return decodeURIComponent((new RegExp(‘[?|&]‘ + name + ‘=‘ + ‘([^&;]+?)(&|#|;|$)‘).exec(location.search)||[,""])[1].replace(/\+/g, ‘%20‘))||null;}

If you use jquery, you can do it in a simpler way:

$.url().param(‘data‘);

Two page parameter JS

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.