Get the App
SLTechnology News&Howtos  ›  Development  › 

How JavaScript data is transmitted on different pages

Shulou Source: shulou.com Published: 2022-06-02 06:16:24 11月12日 Update

This article introduces how JavaScript data is transmitted on different pages. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

In web pages, we often encounter this situation, when we enter information on one page, we will jump to another page, and will pass the information we entered to another page, how to do it?

Today, let's do some practical work. For example, now there are two pages, and when we enter user information on one page, we jump to the other page and display, xx Welcome login interface.

Let's take a look at the design ideas:

The first login page with a submission form, which is submitted by action to the index.html page

For the second page, you can use the parameters of the first page to achieve the effect of transferring data between different pages.

The reason why the second page can use the data of the first page is that it uses the location.search parameter in URL.

On the second page, you need to extract this parameter.

The first step is to use substr to remove it.

The second step uses split ('=') to split keys and values

The first array is the key and the second array is the value.

The implementation code is:

User name: welcome to login! Var span = document.querySelector ('span'); / / get the span tag var myName = location.search.substr (1); / / get the parameter var arr = myName.split (' =') entered on the previous page; / / use the = sign division key and the value span [XSS _ clean] = arr [1] +''/ / to pass the data into span

The running effect is as follows:

About how the transmission of JavaScript data on different pages is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Page data parameters input different information login content that is effect time more user help yes two number reason between code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information MariaDB Shulou Technology Linux