The Location.pathname in JavaScript

Source: Internet
Author: User





1 Location.pathname;
I didn't pay much attention to this before, so I studied.
location.pathname:
Returns the part of the URL after the domain name (domain name IP). For example
http://www.joymood.cn/wordpress/return to/wordpress/, or http://127.0.0.1/index.html
Return to/index.html, Note is a domain name or domain name IP with a URL, build a random HTML file on the disk for location.pathname testing, such as the path on the browser:
C:\Documents
and settings\administrator\ Desktop \testjs.html,
In this way, the resulting result is:
/c:\documents and
Settings\administrator\ Desktop \testjs.html
Since this is mentioned, let's analyze the following URL:
Http://www.joymood.cn:8080/test.php?user=admin&pwd=admin#login
To get the complete URL as above, we use:Location.href;
Get the Transfer Protocolhttp:,We use:Location.protocol;
Get the hostname along with the portwww.joymood.cn:8080, we use:Location.host;
Get host Namewww.joymood.cn, we use:Location.hostname;
Get the host after part does not include the question mark? The latter part of the/test.php, as we have just said:Location.pathname;
Get the question mark in the URL and the part before the pound sign #? user=admin&pwd=admin, we will use:
Location.search;
Get the part before ##login, we will useLocation.hash;
As described above, we can get the parts of a full URL through some properties of the location object.

============================



JavascriptLocation.pathname in the(2012-03-15 22:24:16)
location.pathname "src=" in Location.pathname "align=" Absmiddle " alt=" javascript/HTTP// Simg.sinajs.cn/blog7style/images/common/sg_trans.gif "real_src=" http://simg.sinajs.cn/blog7style/images/common/ Sg_trans.gif "> Reprint





Tags:
Javascript
Pathname
Category: Javascript


Location.pathname:
Returns the part of the URL after the domain name (domain name IP).


For example



    1. http://www.joymood.cn/wordpress/return/wordpress/

    2. Http://127.0.0.1/index.html
      Back to/index.html

Note is a domain name or domain name IP with a URL, on the disk to build a random HTML file for location.pathname testing, such as the path on the browser is: C:\Documents
and settings\administrator\ Desktop \testjs.html,
In this way, the resulting result is:/c:\documents and
Settings\administrator\ Desktop \testjs.html


Parse the following URL:
Http://www.joymood.cn:8080/test.php?user=admin&pwd=admin#login



    1. Location.href: Get the complete URL as above
    2. Location.protocol: Get the Transport protocol http:
    3. Location.host: Get host name together with Port http://www.joymood.cn:8080/
    4. Location.hostname: Get host name http://www.joymood.cn/
    5. Location.pathname: Get the host after part does not include the question mark? The latter part of the/test.php
    6. Location.search: Get the question mark in the URL, then the part before the pound #? user=admin&pwd=admin
    7. Location.hash: Get the part before # #login

The Location.pathname in JavaScript

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.