javascript中的location属性

来源:互联网 发布:送货单样本软件 编辑:程序博客网 时间:2024/05/18 12:30
javascript中的location属性
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 Settings/Administrator/桌面/testjs.html,
这样,得到的结果是:
/C:/Documents and Settings/Administrator/桌面/testjs.html
既然提到这了,那我们就分析下下面的URL:
http://www.joymood.cn:8080/test.php?user=admin&pwd=admin#login
想得到整个如上的完整url,我们用:
location.href;
得到传输协议http:,我们用:location.protocol;
得到主机名连同端口www.joymood.cn:8080,我们用:location.host;
得到主机名www.joymood.cn,我们用:
location.hostname;
得到主机后部分不包括问号?后部分的/test.php,就用我们刚才讲的:location.pathname;
得到url中问号?之后井号#之前的部分?user=admin&pwd=admin,我们就用:
location.search;
得到#之前的部分#login,我们就用location.hash;
经过上面的讲述,我们可以通过location对象的某些属性得到一个完整URL的各个部分。

 

原创粉丝点击