How to get the root path of the system using js _ javascript tips-js tutorial

Source: Internet
Author: User
How to obtain the root path of the system in js is described in this article. If you are interested, refer to it and hope to help you. The Code is as follows:


Function getBasePath (){
Var obj = window. location;
Var contextPath = obj. pathname. split ("/") [1];
Var basePath = obj. protocol + "//" + obj. host + "/" + contextPath;
Return basePath;
}


Javascript Object inclusion

1. window javascript top-level object

2. navigator client browser Information

3. screen client display information

4. url Information accessed in the history browser window

5. location current url Information

The location object contains

For example, the following html address is http: // localhost: 8080/huyao_soccer/huyao/tag/myplugin. jsp.

1. hash

2. The host name and the port number of the current url are returned: localhost: 8080

3. Host Name: localhost

4. Complete href url returned: http: // localhost: 8080/huyao_soccer/huyao/tag/myplugin. jsp

5. pathname:/huyao_soccer/huyao/tag/myplugin. jsp

6. port number: 8080

7. protocol return: http:

8. search slave? Start url Department (query part)
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.