javascript 中的location.pathname

location.pathname: 返回URL的域名(域名IP)后的部分。

例如

  1. http://www.joymood.cn/wordpress/返回/wordpress/
  2. http://127.0.0.1/index.html 返回/index.html

注意是带url的域名或域名IP,在磁盘上随便建个Html文件进行location.pathname测试,如浏览器上的路径是:C:\Documents and Settings\Administrator\桌面\testjs.html, 这样,得到的结果是: /C:\Documents and Settings\Administrator\桌面\testjs.html

分析下面的URL: http://www.joymood.cn:8080/test.php?user=admin&pwd=admin#login

  1. location.href:得到整个如上的完整url
  2. location.protocol:得到传输协议http:
  3. location.host:得到主机名连同端口www.joymood.cn:8080
  4. location.hostname:得到主机名www.joymood.cn
  5. location.pathname:得到主机后部分不包括问号?后部分的/test.php
  6. location.search:得到url中问号?之后井号#之前的部分?user=admin&pwd=admin
  7. location.hash:得到#之前的部分#login
posted @ 2012-10-08 09:17  Grumoon  阅读(203)  评论(0编辑  收藏  举报