Files
freeCodeCamp/guide/chinese/javascript/window-location/index.md
2018-10-16 21:32:40 +05:30

24 lines
843 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Window Location
localeTitle: 窗口位置
---
## 窗口位置
`window.location`对象可用于获取有关当前页面地址URL的信息并将浏览器重定向到新页面。
`window.location`对象可以在没有`window`前缀的情况下编写,就像`location`
#### 一些例子:
* `window.location.href`返回当前页面的hrefURL
* `window.location.hostname`返回Web主机的域名
* `window.location.host`返回主机名和任何关联的端口
* `window.location.pathname`返回当前页面的路径和文件名
* `window.location.protocol`返回使用的Web协议http或https :)
* `window.location.assign()`加载一个新文档
#### 更多信息:
[W3C](https://www.w3schools.com/js/js_window_location.asp)
[MDN](https://developer.mozilla.org/docs/Web/API/Window/location)