JavaScript data transmission between different pages (URL parameter acquisition)

JavaScript data transmission between different pages (URL parameter acquisition)

On web pages, we often encounter this situation: when we enter information on a certain page, it will jump to another page and pass the information we entered to another page. How do we do it?
Today, let’s try it out in practice. For example, there are two pages now. When we enter user information on one page, we will jump to another page and display the xx welcome to login interface.

Let’s take a look at the design ideas first:

  • The first login page contains a submission form, and action is submitted to index.html page
  • The second page can use the parameters of the first page, thus achieving the effect of transferring data between different pages
  • The second page can use the data from the first page because it uses the location.search parameter in the URL.
  • In the second page, this parameter needs to be extracted.
  • The first step is to use substr to remove it?
  • The second step is to use split('=') to separate the key and value
  • The first array is the key and the second array is the value

The implementation code is:

<body>
    <form action="index.html">
        Username: <input type="text" name = 'uname'>
        <input type="submit" value="Submit">
    </form>
</body>

<body>
    <div><span style="font-weight:700; color:blue"></span>Welcome to log in! </div>
    <script>
       var span = document.querySelector('span'); //Get the span tag var myName = location.search.substr(1); //Get the parameter entered on the previous page var arr = myName.split('='); //Use the = sign to split the key and value span.innerHTML = arr[1] + '' //Pass the data into span
    </script>
</body>

The running effect is:

This concludes this article on the transmission of JavaScript data on different pages (URL parameter acquisition). For more information on the transmission of JavaScript data on different pages, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Summary of 4 methods for front-end JS to obtain URL parameters
  • Several common methods for native JS to obtain URL link parameters
  • Two methods to obtain URL parameters based on JavaScript
  • Detailed explanation of the getRequest() method example for obtaining URL parameters in js
  • JS obtains url parameters and sends POST request method in json format
  • Detailed explanation of how to get the querystring parameter in the URL in JavaScript
  • JavaScript method to obtain URL parameters

<<:  MySQL database transaction example tutorial

>>:  About input file control and beautification

Recommend

Detailed tutorial on how to delete Linux users using userdel command

What is serdel userdel is a low-level tool for de...

Use semantic tags to write your HTML compatible with IE6,7,8

HTML5 adds more semantic tags, such as header, fo...

User experience of portal website redesign

<br />From the launch of NetEase's new h...

A collection of common uses of HTML meta tags

What is a mata tag The <meta> element provi...

Share 20 JavaScript one-line codes

Table of contents 1. Get the value of browser coo...

Steps for Vue to use Ref to get components across levels

Vue uses Ref to get component instances across le...

Introduction to HTML DOM_PowerNode Java Academy

What is DOM? With JavaScript, you can reconstruct...

A brief discussion on VUE uni-app's commonly used APIs

Table of contents 1. Routing and page jump 2. Int...

CSS3 filter code to achieve gray or black mode on web pages

front end css3,filter can not only achieve the gr...

JavaScript removes unnecessary properties of an object

Table of contents Example Method 1: delete Method...