---
title: "window.location or window.location.href?"
author: "wasw100"
date: "2010-01-26T09:08:42Z"
tags: []
categories: ["Web前端"]
slug: "window-location-or-window-location-href"
draft: false
lastmod: "2010-01-26T09:08:42Z"
id: 579780
url: "https://wasw100.iteye.com/blog/579780"
---

参考：1.[http://www.javascriptkit.com/jsref/location.shtml](http://www.javascriptkit.com/jsref/location.shtml)  
         2.[http://www.highdots.com/forums/javascript-discussion-multi-lingual/window-location-window-location-href-276539.html](http://www.highdots.com/forums/javascript-discussion-multi-lingual/window-location-window-location-href-276539.html)

 

 

写道

Location contains information about the current URL of the browser. The most common usage of Location is simply to use it to automatically navigate the user to another page:

```
<script type="text/javascript">
window.location="http://www.google.com"
</script>
```

 

所以推荐使用window.location，包含更多信息

 

理由（参考文章的第二篇）

写道

Although "window.location.href" also seems to work. The "entire URL"  
href property (of window.location) appears to be a bit redundant. Other  
properties of "windows.location" could be useful for reading or changing  
portions of the URL like domain/host names and port numbers (which are  
sometimes not stated - permitted to remain the default).

 

 

--EOF--