Home > Web Front-end > JS Tutorial > How to get basePath in js file to deal with js path problem_javascript skills

How to get basePath in js file to deal with js path problem_javascript skills

WBOY
Release: 2016-05-16 17:29:16
Original
1291 people have browsed it

The problem of js path is sometimes difficult to deal with. In jsp, we can use el expression to directly obtain basePath, but el expression cannot be used in a separate js file, and we do not want to write a separate variable in jsp. You can use the following Method:

Copy code The code is as follows:

var location = (window.location '') .split('/');
var basePath = location[0] '//' location[2] '/' location[3];
var url = basePath '/js/xxx.js';
Related labels:
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