window.open()
window.open(“地址”,“打开方式”,“尺寸”)
window.open(‘test.html’, ‘_self’, ‘width=200, height=200’);
打开方式:
_blank新的窗口打开
_self在当前窗口打开
window.screen屏幕对象
availHeight 高度
availWidth 宽度
window.navigator浏览器对象
示例:
//判断用户使用的浏览器
var nv = window.navigator.userAgent;
if (nv.indexOf(‘Chrome’) != -1) {
alert(‘当前用户浏览器是谷歌’);
} else if (nv.indexOf(‘Firefox’) != -1) {
alert(‘当前用户浏览器是火狐’);
}else if (nv.indexOf(‘MSIE’) != -1 || isIE()) {
alert(‘当前用户浏览器是IE浏览器’);
};
function isIE() { // 判断是否是ie10的浏览器
if (!!window.ActiveXObject || “ActiveXObject” in window){
return true;
}else{
return false;
}
};
window.location地址对象
window.location.href = ‘test.html’;
window.history 历史对象
window.history.go(1); //前进
window.history.go(-1); //后退
localStorage 本地存储对象
存储对象, 可以用来存储数据, 和cookie相似, 区别是它是为了更大容量存储设计的, 在使用上也更加方便。
localStorage 数据一直存在
写入:
localStorage.setItem(‘name’,‘小王’);
读取:
localStorage.getItem(‘name’)
移除:
localStorage.removeItem(‘name’);
清空:
localStorage.clear();
sessionStorage浏览器存储对象
存储对象, 可以用来存储数据, 和cookie相似, 区别是它是为了更大容量存储设计的, 在使用上也更加方便
sessionStorage 当窗口关闭后 数据就被清空了
写入:
sessionStorage.setItem(‘name’,‘小王’);
读取:
sessionStorage.getItem(‘name’)
移除:
sessionStorage.removeItem(‘name’);
清空:
sessionStorage.clear();