freeCodeCamp/guide/chinese/javascript/window-location/index.md

24 lines
843 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
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)