freeCodeCamp/guide/chinese/javascript/tutorials/get-current-url-in-javascript/index.md

15 lines
370 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: Get Current Url in JavaScript
localeTitle: 在JavaScript中获取当前URL
---
要获取**当前网址**
```
var url = window.location.href;
```
要获取**当前路径**
```
var path = window.location.path;
```
有关位置对象及其属性的更多信息,请参见[此处](https://developer.mozilla.org/en-US/docs/Web/API/Window/location) 。