Heim  >  Artikel  >  Web-Frontend  >  js获取系统的根路径实现介绍_javascript技巧

js获取系统的根路径实现介绍_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:23:06968Durchsuche
复制代码 代码如下:

function getBasePath(){
var obj=window.location;
var contextPath=obj.pathname.split("/")[1];
var basePath=obj.protocol+"//"+obj.host+"/"+contextPath;
return basePath;
}

javascript对象包含

1.window javascript的顶层对象

2.navigator 客户端浏览器的信息

3.screen 客户端显示屏的信息

4.history 浏览器窗口访问过的url信息

5.location 当前url信息

其中location对象包含

比如有这样一个html地址 http://localhost:8080/huyao_soccer/huyao/tag/myplugin.jsp

1.hash

2.host 主机名和当前url的端口号 返回:localhost:8080

3.hostname 主机名 返回:localhost

4.href 完整的url 返回:http://localhost:8080/huyao_soccer/huyao/tag/myplugin.jsp

5.pathname 返回当前url的路径部分 返回:/huyao_soccer/huyao/tag/myplugin.jsp

6.port 端口号 返回:8080

7.protocol 协议 返回: http:

8.search 从?开始的url部门(查询部分)
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn