Home > Web Front-end > JS Tutorial > body text

JS gets the current URL and host address project root path_javascript skills

WBOY
Release: 2016-05-16 17:14:10
Original
1267 people have browsed it

Copy code The code is as follows:

//Get the current URL, such as: http:// localhost:8080/Tmall/index.jsp
var curWwwPath=window.document.location.href;

//The directory after obtaining the host address is: /Tmall/index.jsp
var pathName =window.document.location.pathname;
var pos=curWwwPath.indexOf(pathName);

//Get the host address, such as: http://localhost:8080
var localhostPaht=curWwwPath .substring(0,pos);

//Get the project name with "/", such as: /Tmall
var projectName=pathName.substring(0,pathName.substr(1).indexOf( '/') 1);
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template