window.location 对象在编写时可不使用 window 这个前缀。 一些例子:
一些实例:
location.hostname 返回 web 主机的域名
location.pathname 返回当前页面的路径和文件名
location.port 返回 web 主机的端口 (80 或 443)
location.protocol 返回所使用的 web 协议(http:// 或 https://)
?
<script type="text/javascript"> var hostname=window.location.hostname; document.writeln(hostname); </script>
?
得到你的域名地址,例如:http://www.onestopweb.cn/
?
原文:http://onestopweb.iteye.com/blog/2268670