Fork me on GitHub

李可

导航

JavaScript:Location

读取、设置url

在url中输入:http://www.cnpiont.com:8090/index.html?user=like&pwd=123#title
Console输入:

document.write(
'protocol-->'+location.protocol+'<br/>',
'host-->'+location.host+'<br/>',
'hostname-->'+location.hostname+'<br/>',
'href-->'+location.href+'<br/>',
'pathname-->'+location.pathname+'<br/>',
'search-->'+location.search+'<br/>',
'hash-->'+location.hash+'<br/>'
)
/**结果
protocol-->http:
host-->www.cnpiont.com:8090
hostname-->www.cnpiont.com
href-->http://www.cnpiont.com:8090/index.html?user=like&pwd=123#title
pathname-->/index.html
search-->?user=like&pwd=123
hash-->#title
*/

刷新浏览器

/*
1,history.go(0) 
2,location.reload() 
3,location=location 
4,location.assign(location) 
5,location.replace(location) 
6,window.navigate(location) //chrome未成功
7,document.execCommand('Refresh') //chrome未成功
8,document.URL=location.href//chrome未成功
*/

posted on 2016-11-28 11:20  李可在江湖  阅读(263)  评论(0编辑  收藏  举报