MoreLesson 286Free preview
Get Current URL
This lesson is part of How To · All levels
Summary
The window.location object stores information about the address of the page being opened. From this object you can read the full URL, protocol, host name, path, query string, and hash. To take the value of a particular parameter, use URLSearchParams so that you don't have to cut the string manually.
Key points
- Location.href contains the full URL of the page
- Location.search contains query string including question mark
- Location.hash contains the section after hash (#)
- Location.pathname contains a page line without a domain
- URLSearchParams make it easy to read the query parameters
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.