问题
I have a URL like below :
http://localhost:1692/fa/Help.aspx#Help
the code below returns that :
alert(document.URL);
I only want to get the http://localhost:1692 part of this URL.
How can I get it with jQuery or JavaScript?
回答1:
Try this:
alert( location.protocol + "//" + location.host )
回答2:
location.protocol + '//' + location.host
And, if you want, you have these other properties:
hashsearch- url querystringhostname- only the hostname (without port)port- only the port numberpathname- the local url
来源:https://stackoverflow.com/questions/8547709/working-with-uri-in-javascript