suppose that you have a page with this address: http://sub.domain.com/virtualPath/page.htm
.(假设您有一个具有以下地址的页面: http://sub.domain.com/virtualPath/page.htm
: http://sub.domain.com/virtualPath/page.htm
。)
use the following in page code to achive those results:(使用页面代码中的以下内容获得这些结果:)
-
window.location.host
: you'll get sub.domain.com:8080
or sub.domain.com:80
(window.location.host
:您将获得sub.domain.com:8080
或sub.domain.com:80
)
-
window.location.hostname
: you'll get sub.domain.com
(window.location.hostname
:您将获得sub.domain.com
)
-
window.location.protocol
: you'll get http:
(window.location.protocol
:您将获得http:
)
-
window.location.port
: you'll get 8080
or 80
(window.location.port
:您将获得8080
或80
)
-
window.location.pathname
: you'll get /virtualPath
(window.location.pathname
:您将获得/virtualPath
)
-
window.location.origin
: you'll get http://sub.domain.com
*****(window.location.origin
:您将获得http://sub.domain.com
*****)
Update: about the .origin(更新:关于.origin)
***** As the ref states, browser compatibility for window.location.origin
is not clear.(*****如参考文献所述, window.location.origin
浏览器兼容性尚不清楚。)
I've checked it in chrome and it returned http://sub.domain.com:port
if the port is anything but 80, and http://sub.domain.com
if the port is 80.(我已经在Chrome检查,它返回http://sub.domain.com:port
如果端口是什么,但80和http://sub.domain.com
如果端口为80。)
Special thanks to @torazaburo for mentioning that to me.(特别感谢@torazaburo向我提及。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…