Wednesday, 7 September 2016

Get the current URL with JavaScript?



All I want is to get the website URL. Not the URL as taken from a link. On the page loading I need to be able to grab the full, current URL of the website and set it as a variable to do with as I please.


Answer



Use:



window.location.href 



As noted in the comments, the line below works, but it is bugged for Firefox.



document.URL;


See URL of type DOMString, readonly.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...