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:

window.location.href 
click below button to copy the code. By JavaScript tutorial team

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:

window.location.href
click below button to copy the code. By JavaScript tutorial team

Solution 4:

To get the path, we can use:

alert("Url  ="+document.location);
alert("PathName  ="+ window.location.pathname);// Returns path only
alert("url  ="+window.location.href);// Returns full URL
click below button to copy the code. By JavaScript tutorial team

Solution 5:

  • Use window.location.href to get the complete URL.
  • Use window.location.pathname to get URL leaving the host.

Related Searches to javascript tutorial - Current URL with javascript