JS Get URL Multiple parameters

Source: Internet
Author: User

function GetQueryString(name) {       var reg = new RegExp( "(^|&)" + name + "=([^&]*)(&|$)" );       var r = window.location.search.substr(1).match(reg);       if (r!= null ) return unescape(r[2]); return null ; } // 调用方法 alert(GetQueryString( "参数名1" )); alert(GetQueryString( "参数名2" )); alert(GetQueryString( "参数名3" ));Cases:

If the Address bar URL is:abc.html?id=123&url=http://www.maidq.com

So, but you use the above method to invoke: Alert (getquerystring ("url"));

A dialog box pops up: The content is http://www.maidq.com

If using: Alert (getquerystring ("id")), then the popup content is 123;

Of course, if you do not pass parameters, such as your address is abc.html back no parameters, the force output call results sometimes error:

So we have to add a judgment to determine if the argument we requested is empty, first assign the value to a variable:

var myurl=GetQueryString( "url" ); if (myurl != null && myurl.toString().length>1) {     alert(GetQueryString( "url" )); }

This will not be an error!

Reference: http://www.cnblogs.com/fishtreeyu/archive/2011/02/27/1966178.html

JS Get URL Multiple parameters

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.