Use jquery to obtain the parameters passed by the URL of the current page

Source: Internet
Author: User

/* -- Get the parameter passed by the webpage -- */function request (paras) {var url = location. href; var parastring = URL. substring (URL. indexof ("? ") + 1, URL. length ). split ("&"); var paraobj = {} for (I = 0; j = parastring [I]; I ++) {paraobj [J. substring (0, J. indexof ("= ")). tolowercase ()] = J. substring (J. indexof ("=") + 1, J. length);} var returnvalue = paraobj [paras. tolowercase ()]; If (typeof (returnvalue) = "undefined") {return ";} else {return returnvalue;} You can call this request, here you can call request ("ID ")
Jquery obtains the URL Information of the current page

 

To improve the user experience, you need to highlight the category of the current page in the navigation menu to let users know where they are currently on the website. I have been modifying the content in the program for a long time, so I am very troublesome. I thought about whether I can use jquery to obtain the URL of the current page to achieve this effect. Of course, the answer is yes.

Most importantlyObtain the details of the current URL, You can determine, this requires the useFunctions of jquery to obtain a URL. I would like to share with you that some friends who have never used this method can try it.

Sets or obtains the specified file name or path of an object. Window. Location. pathname

Set or retrieve the entire URL as a string. Window. Location. href

Set or obtain the port number associated with the URL. Window. Location. Port

Set or obtain the protocol section of the URL. Window. Location. Protocol

Set or obtain the segment following the # In the href attribute. Window. Location. Hash

Set or obtain the hostname and port numbers of the location or URL. Window. Location. Host

Set or obtain the Section following the question mark in the href attribute. Window. Location. Search

Window. Location
Attribute Description
Hash Set or get
Segment following the # In the href attribute.
Host Set or obtain the hostname and port numbers of the location or URL.
Hostname Set or obtain the Host Name of the location or URL.
Href Set or retrieve the entire URL as a string.
Pathname Sets or obtains the specified file name or path of an object.
Port Set or obtain
The port number associated with the URL.
Protocol Set or obtain the protocol section of the URL.
Search Set or obtain the Section following the question mark in the href attribute.

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.