---
title: "javascript中获取浏览器的url"
author: "longsy"
date: "2009-09-03T18:47:59Z"
tags: []
slug: "javascript-url"
draft: false
lastmod: "2009-09-03T18:47:59Z"
id: 461628
url: "https://longsy.iteye.com/blog/461628"
---

document.location

location.href(与location.toString()一样)

location

document.URL

 

在IE中document.URL与其它三个稍有不同

IE6~7（假设文件保存的桌面上,location.html）

```
<SCRIPT LANGUAGE="JavaScript">
<!--
	document.write(location.href);
	document.write("<br>");
	document.write(location);
	document.write("<br>");
	document.write(document.location);
	document.write("<br>");
	document.write(document.URL);
//-->
</SCRIPT>
```

 结果为:

file:///C:/Documents%20and%20Settings/Administrator/桌面/location.html  
file:///C:/Documents%20and%20Settings/Administrator/桌面/location.html  
file:///C:/Documents%20and%20Settings/Administrator/桌面/location.html  
file://C:\\Documents and Settings\\Administrator\\桌面\\location.html

 

在firefox,Opera,Google中四个语句展示结果均相同