---
title: "js 获取当前web应用的上下文路径"
author: "zwt2001267"
date: "2013-12-29T17:34:39Z"
tags: []
categories: ["Web前端"]
slug: "js-web"
draft: false
lastmod: "2013-12-29T17:34:39Z"
id: 1997086
url: "https://hbzwt.iteye.com/blog/1997086"
---

function getWebRootPath() {  
    var webroot=document.location.href;  
    webroot=webroot.substring(webroot.indexOf('//')+2,webroot.length);  
    webroot=webroot.substring(webroot.indexOf('/')+1,webroot.length);  
    webroot=webroot.substring(0,webroot.indexOf('/'));  
    var rootpath="/"+webroot;  
    return rootpath;  
}