JavaScript-If I set a username in index.html, and then I jump from this page to the B.html page, how can I use this user name for this page?

Source: Internet
Author: User
If I set a username in index.html, and then I jump to the b.html page from this page, how can I use this user name for this page?

Reply content:

If I set a username in index.html, and then I jump to the b.html page from this page, how can I use this user name for this page?

In principle, it is used SESSION or COOKIE implemented. But if you are not a dynamic program (based on other dynamic programming languages like PHP), just an HTML file, you can rewrite the URL and add the anchor information:

去B页面

on page B, you need to use JS to get this value, such as:

var username = window.location.hash;

Of course, there are other, such as 隐藏域 . In short, the simplest is SESSION or COOKIE .

Session | | Cookies

Session or Cookie

If you do not have a service side and do not consider other security issues, you can place it in a URL.

Server-side do: Session

Client: URL contains parameters, cookies

If only for the front-end page display, can be stored in the following several common places:
1. URL
2. Cookies
3, Localstorage
4, Sessionstorage

Session or Cookie.

  • 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.