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?
The current URL can be obtained by using the 'URL' property of the Document object which contains information about the current URL. The 'URL' property returns a string with the full location of the current page, along with containing the string having the HTTP protocol such as ( http://).
var lighboxHeight = (pagenumber-1)*window.
checkValidity() method is used to check if a string in <input> element's value attribute is URL . The checkvalidity() method returns true if the value is a proper URL and false if the input is not a proper URL.
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.
That's weird, cause it works for me. You might try:
Look the same question here : Get current URL in web browser
Use :
console.log(document.URL);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With