javascript tutorial - [Solved-5 Solutions] Current URL with javascript - javascript - java script - javascript array
Problem:
How to get the current URL with javaScript?
Solution 1:
Use:
Solution 2:
Use window.location
for read and write access to the location object associated with the current frame. If we just want to get the address as a read-only string, we may usedocument.URL
, which should contain the same value as window.location.href
.
Solution 3:
Gets the current page URL:
Solution 4:
To get the path, we can use:
Solution 5:
- Use window.location.href to get the complete URL.
- Use window.location.pathname to get URL leaving the host.