How to get the current page URL using JavaScript?
Hello everyone! I'm a beginner in JavaScript and writing a small web application. I need to get the full address of the current page to, for example, pass it to a feedback form or save it in localStorage for analytics.
I tried writing something like `window.url`, but it doesn't work. Then I googled that there is a `location` object, but I got confused about its properties. I need exactly what is displayed in the browser's address bar, including the protocol (http/https), domain, path, and possibly query parameters.
Here is an example of my attempt:
```javascript
let currentUrl = window.location;
console.log(currentUrl);
```
The console outputs an object, not a string. How can I get the address as a string? And is it possible to split the URL into parts: protocol separately, host separately, path separately? I would be grateful.
No answers yet.
Log in to leave an answer