How to obtain link parameters in JavaScript example _ javascript skills

Source: Internet
Author: User
This article describes how to obtain link parameters in JavaScript. If you want to use url to transmit parameters, you should be familiar with it. For example:

Http://www.softwhy.com/home.php? Mod = space & do = home & view = all

Since parameters are passed, we naturally need to obtain the passed parameters. Of course, there are many ways to obtain parameters. Here we will introduce one of them and share them with you, the Code is as follows:

var url="http://www.softwhy.com/home.php?mod=space&do=home&view=all";if(url.indexOf("?")!=-1) {var str=url.substr(url.indexOf("?")+1);strs=str.split("&");for(i=0;i
 
  ');}}
 

In the above link:

1. The length of strs. length is 3.
2. strs [0]. split ("=") [0] Is mod, and strs [0]. split ("=") [1] is space.
3. strs [1]. split ("=") [0] is do, and strs [1]. split ("=") [1] is home.

And so on.

We will share with you three examples of code for obtaining the address bar parameters in JS.

Sometimes, we need to get the address bar parameter value of the static page. JS is the easiest way to use. The following three function codes are collected for obtaining the address bar parameters using javaScript, which is easy to use, the following code is shared with you one by one:

JS to obtain the address bar string parameters, Method 1:

Related Article

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.