Home >Web Front-end >JS Tutorial >How to get the url of the website in js

How to get the url of the website in js

hzc
hzcOriginal
2020-06-17 17:10:504586browse

How to get the url of the website in js

How to get the url of the website with js

1. document.documentURI

document.documentURI;
// "https://i.cnblogs.com/EditPosts.aspx?opt=1"

2. document.URL

document.URL;
// "https://i.cnblogs.com/EditPosts.aspx?opt=1"

Note:

1. The functions of the two attributes are exactly the same. Both return a string of the current web page URL;

2. document.documentURI inherits from the Document interface and is applicable to all documents;

3. document.URL inherits from the HTMLDocument interface and is only applicable to HTML documents;

Recommended tutorial: " JS tutorial

The above is the detailed content of How to get the url of the website in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn