location.href/location.search/location.pathname区别及用法
来源:互联网 发布:包丁藤四郎极化数据 编辑:程序博客网 时间:2024/06/05 03:35
location.href/location.search/location.pathname区别及用法:
location.pathname: 返回URL的域名(域名IP)后的部分。
例如 http://www.example.com/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.example.com:8080/test.PHP?user=admin&pwd=admin#login
想得到整个如上的完整url,我们用:location.href;
得到传输协议http:,我们用:location.protocol;
得到主机名连同端口www.example.com:8080,我们用:location.host;
得到主机名www.joymood.cn,我们用:location.hostname;
得到主机后部分不包括问号?后部分的/test.php,就用我们刚才讲的:location.pathname;
得到url中问号?之后井号#之前的部分?user=admin&pwd=admin,我们就用: location.search;
得到#之前的部分#login,我们就用location.hash
如上,我们可以通过location对象的某些属性得到一个完整URL的各个部分。
js中的应用:
无刷新更新地址栏:
<script>
$(document).ready(function(){
//更新地址栏
top.window.history.replaceState(null, null, "#" + window.location.pathname + location.search);
});
</script>
- location.href/location.search/location.pathname区别及用法
- location.href/location.search/location.pathname区别及用法
- location.href和location.search区别
- js中的location的href和pathname,search
- location.href 与 location.search
- location.href 与 location.search
- location.href,location.replace(),location.reload()用法和区别
- location.href的用法
- location.href用法
- location.href的用法
- location.href用法总结
- location.href的用法
- location.href 用法
- location.href的用法
- location.href的用法
- location.href用法总结
- location.href用法总结
- location.href用法
- 触动精灵 获取外网IP
- Beautiful Arrangement II问题及解法
- percona5.6中对索引的优化-实践1
- kafka_2.11-0.8.2.1生产者producer的Java实现
- 信号量的用法和解释,sem_init,sem_wait
- location.href/location.search/location.pathname区别及用法
- 格式化字符串
- mysql 中文排序 数字排序
- 《Towards Good Practices for Very Deep Two-Stream ConvNets》阅读笔记
- Python常见问题整理
- HDU 3613 Best Reward(扩展KMP模板)
- redis缓存数据库操作
- Android TextView去掉paddingTop和paddingBottom
- requests库入门-6-Params参数请求举例