如何使用jquery或javascript获取基本URL? [英] How to get base url with jquery or javascript?

查看:100
本文介绍了如何使用jquery或javascript获取基本URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在joomla php中,我可以使用$this->baseurl来获取基本路径,但是我想在jquery中获取基本路径.

In joomla php there I can use $this->baseurl to get the base path, but I wanted to get the base path in jquery.

基本路径可以是以下任何示例:

The base path may be any of the following example:

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];

这篇关于如何使用jquery或javascript获取基本URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆