Ways to get Address bar parameters using JavaScript

Source: Internet
Author: User

 /*  * * get Address bar parameter * * @example geturlstring (' id ') * * * @desc call with judgment, guarantee the program will not go wrong * var myurl = geturlstring (' id ');    * if (Myurl! = null && myurl.tostring (). length > 1) {* Alert (geturlstring ("id"));  *} * * @param string param to get the parameter name in the Address bar * @return String Value * @type String * * @name geturlstring () * * @author iceman/[email protected]  */ function   Geturlstring (param) { var  svalue = Location.search.match (new  RegExp ("[\?\&]" + M + "= ([^\&]*] (\&?)", "    I " return  svalue? decodeURI (Svalue[1 

Call the time unified to do such a judgment, to avoid you do not pass arguments, such as your address is abc.html back no parameters, the force output call results sometimes error

function () {        var myurl = getparm ("id");     if null && myurl.tostring (). length > 1) {        alert (Getparm ("id"));}    }

This will not be an error!

Note: ECMAScript v3 has removed the unescape () function from the standard and opposes its use, so it should be replaced with decodeURI () and decodeURIComponent ().

Ways to get Address bar parameters using JavaScript

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.