如何使用jquery或javascript获取基本网址?
2022-08-30 00:48:17
在joomla php中,我可以用来获取基本路径,但我想在jquery中获取基本路径。$this->baseurl
基本路径可以是以下任何示例:
http://www.example.com/
http://localhost/example
http://www.example.com/sub/example
也可能改变。example
在joomla php中,我可以用来获取基本路径,但我想在jquery中获取基本路径。$this->baseurl
基本路径可以是以下任何示例:
http://www.example.com/
http://localhost/example
http://www.example.com/sub/example
也可能改变。example
这个将帮助您...
var getUrl = window.location;
var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
我认为这对你很有效:
var base_url = window.location.origin;
var host = window.location.host;
var pathArray = window.location.pathname.split( '/' );