`
tianqing52
  • 浏览: 42922 次
  • 性别: Icon_minigender_2
  • 来自: 深圳
社区版块
存档分类
最新评论

转:avascript:window.location 详细用法

阅读更多
原文:http://xiarilian12.iteye.com/blog/520365
http://localhost/test/test.htm?id=1

<html>
Java代码 
<head> 
</head> 
<body> 
<script languge=javascript> 
alert(window.location.pathname);   --返回   /test/test.htm 
alert(window.location.search);        --返回   ?id=1 
alert(window.location.href);             --返回   http://localhost/test/test.htm?id=1 
</script> 
</body> 
</html> 


location对象 含有当前URL的信息. 属性 href 整个URL字符串.
protocol 含有URL第一部分的字符串,如http:
host 包含有URL中主机名:端口号部分的字符串.如//www.cenpok.net/server/
hostname 包含URL中主机名的字符串.如http://www.cenpok.net ;
port 包含URL中可能存在的端口号字符串.
pathname URL中"/"以后的部分.如~list/index.htm
hash "#"号(CGI参数)之后的字符串.
search "?"号(CGI参数)之后的字符串.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics