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?
3 Answers 3
window.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.
-
true, but the way he worded the question i'm assuming he actually has loaded the page with that urlLordZardeck– LordZardeck2012年02月05日 22:41:12 +00:00Commented Feb 5, 2012 at 22:41
-
In my browser window, I see fr.example.myhost.com while when I do window.location, I see example.myhost.comAlon– Alon2012年02月05日 22:41:38 +00:00Commented Feb 5, 2012 at 22:41
-
do you have an actual webpage example?vol7ron– vol7ron2012年02月05日 22:53:07 +00:00Commented Feb 5, 2012 at 22:53
That's weird, cause it works for me. You might try:
- window.location.host
- window.location.hostname
- window.location.origin
alert(location)
?location.href
should give you the entire url.