Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:29:161208browse

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';
Statement:
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