history对象保存了用户在浏览器中访问页面的历史记录。
history.back() 回到历史记录的上一步 相当于使用了history.go(-1).-2回到历史记录的前两步。
history.forward() 回到历史记录的下一步 相当于使用了history.go(1).根据历史记录前进。
history.go(-n) 回到历史记录的前n步 。
history.go(n)回到历史记录的后n步。
var btn=document.getElementById("btn");
//点击btn按钮时回到历史记录的上一步
btn.onclick=function(){
history.back();
}
screen对象:包含有关客户端显示屏幕的信息。
screen.availWidth:返回可用的屏幕宽度。
screen.availHeight:返回可用的屏幕高度。
console.log("页面宽:"+screen.availWidth);
console.log("页面高:"+screen.availHeight);//屏幕可用的宽高
console.log("pageWidth:"+window.innerWidth);
console.log("pageHeight:"+window.innerHeight);//窗口宽高
navigator对象:
学习目标:
扫描二维码关注公众号,回复:
2841032 查看本文章
- navigator对象的userAgent属性
- 判断浏览器的类型
- 判断设备的终端是移动还是PC
userAgent:用来识别浏览器名称、版本、引擎以及操作系统等信息的内容。
var explor=navigator.userAgent;
alert(explor);
indexOf()方法返回某个指定的字符串值在字符串中首次出现的位置,如果没有出现过,返回-1.在长的字符串中是否包含一个短的字符串。
判断使用的是什么浏览器:
function getBrower(){
//获取userAgent属性
var explorer=navigator.userAgent.toLowerCase(),browser;
if(explorer.indexOf("msie")>-1){
browser="IE";
}else if(explorer.indexOf("chrome")>-1){
browser="chrome";
}else if(explorer.indexOf("opera")>-1){
browser="opera";
}else if(explorer.indexOf("safari")>-1){
browser="safari";
}
return browser;
}
var explorer=getBrower();
console.log("您当前使用的是:"+explorer+"浏览器")
//您当前使用的是:chrome