---
title: "js获取网站路径"
author: "gaoke"
date: "2013-04-02T11:36:47Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2013-04-02T11:36:47Z"
id: 1840628
url: "https://gaoke.iteye.com/blog/1840628"
---

var tempContext;  
     var tempPathName = window.location.pathname;  
     tempContext = tempPathName.substring(1,tempPathName.length);  
     context = tempContext.substring(0,tempContext.indexOf("/"));  
     path = window.location.protocol+"//"+window.location.host+"/"+context;