javascript 中的location.pathname

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

例如

http://www.joymood.cn/wordpress/返回/wordpress/
http://127.0.0.1/index.html 返回/index.html
注意是带url的域名或域名IP,在磁盘上随便建个Html文件进行location.pathname测试,如浏览器上的路径是:C:Documents and SettingsAdministrator桌面 estjs.html, 这样,得到的结果是: /C:Documents and SettingsAdministrator桌面 estjs.html

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

location.href:得到整个如上的完整url
location.protocol:得到传输协议http:
location.host:得到主机名连同端口www.joymood.cn:8080
location.hostname:得到主机名www.joymood.cn
location.pathname:得到主机后部分不包括问号?后部分的/test.php
location.search:得到url中问号?之后井号#之前的部分?user=admin&pwd=admin
location.hash:得到#之前的部分#login
---------------------
作者:grumoon
来源:CSDN
原文:https://blog.csdn.net/grumoon/article/details/38382003
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/feiwenstyle/p/10730601.html