location地址栏对象
window.location(地址,对应的是浏览器的地址栏)。
location.href=”网页地址/电子邮件等”;
console.log(window.location.hash);//锚点,一般用于做单页面应用时比较常用。
console.log(window.location.host);//主机:主机名+端口号
console.log(window.location.hostname);//主机名
console.log(window.location.pathname);//路径名
console.log(window.location.port);//端口
console.log(window.location.protocol);//协议
console.log(window.location.search);//一些参数,一般用于跟后台交互时使用,
搜索时通过地址栏给后台传入参数,后台根据参数返回,参数在地址栏中wd中,是在s?文件中(?后边表示需要获取的参数)
定时跳转:
提示:(倒计时,定时跳转
1先获取事件2间歇定时器3设置跳转内部文本innerHTML,4秒数不能写死num,
5判断num为0清除定时器6跳转location.href=skip.href;)
var timer=null;
var skip=document.getElementById('skip');
var num=5;
timer=setInterval(function () {//添加间歇定时器
num--;
skip.innerHTML="注册成功,本页面将在"+ num +"秒后自动跳转";//秒数不能写死
if (num===0) {
clearInterval(timer);//清除定时器
location.href=skip.href;
};
},1000);
其它三个对象:
navigator对象:
常用属性navigator.userAgent(用户代理):可以获取客户端的一些信息,代理检测。
history对象:history.forward();前进history.back();后退或者用history.go(-1或者1);(0是当前页面-1是历史页面,1是前进页面)
screen.width;屏幕的宽度
screen.height;屏幕的高度
screen.availwidth;可用宽度
screen.availheight;可用高度