How do I get the website URL?
Not the URL as taken from a link. On the loading page, I want to get the full, current URL of the current web page and store its value in a variable.
How do I get the website URL? Not the URL as taken from a link. On the loading page, I want to get the full, current URL of the current web page and store its value in a variable. |
|||||||||
|
Use:
As noted in the comments, the line below works but is bugged for Firefox.
|
|||||||||||||||||||||
|
JavaScript provides you many methods to retrieve and change the current URL which is displayed in browser's address bar. All these methods uses the Location object, which is a property of the Window object. You can create a new Location object that has the current URL as follows:
Basic Structure of a URL
With these Location object properties you can access all of these URL components
I Hope you got your answer.. |
|||||||||||||
|
The same question has been asked less than 24 hours ago. To quote myself:
|
|||||
|
Gets the current page URL:
|
|||||||||||||||||||||
|
Use: As noted above, |
|||
|
To get the path, you can use:
|
|||
|
|
|||||
|
The above code can also help someone |
|||||||||||||||||
|
For complete URL with query strings:
For host URL:
|
|||||||||
|
Way to get the current location object is Compare this to And, all modern browsers map In reality, for cross browser safety, you should use |
|||
|
You can get current url location with hash tag by using : JavaScript :
Jquery :
|
||||
|
In jstl we can access current url path using
Ex: in the page |
|||
|
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?