I have a website on a host example.myhost
but I also have a sub-domain for French fr.example.myhost
which is different than example.myhost.
If I'm at fr.example.myhost
and I use window.location.href
, I get example.myhost
instead of fr.example.myhost
.
How do I get the URL typed in the address bar of the browser?
I have a website on a host example.myhost.com
but I also have a sub-domain for French fr.example.myhost.com
which is different than example.myhost.com.
If I'm at fr.example.myhost.com
and I use window.location.href
, I get example.myhost.com
instead of fr.example.myhost.com
.
How do I get the URL typed in the address bar of the browser?
Share Improve this question edited Feb 5, 2012 at 22:33 Christofer Eliasson 33.9k7 gold badges76 silver badges103 bronze badges asked Feb 5, 2012 at 22:28 AlonAlon 3,90610 gold badges46 silver badges65 bronze badges 12 | Show 7 more comments3 Answers
Reset to default 15window.location
The subdomain shouldn't make a difference. If, however, you've typed the URL in the address bar, after the page has loaded (but not hit enter), then that's a different story altogether.
That's weird, cause it works for me. You might try:
- window.location.host
- window.location.hostname
- window.location.origin
Look the same question here : Get current URL in web browser
Use :
console.log(document.URL);
alert(location)
? – Douglas Commented Feb 5, 2012 at 22:31location.href
should give you the entire url. – SeanCannon Commented Feb 5, 2012 at 22:33