Copy codeThe 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)