window窗口操作
<<!DOCTYPE html>
<html>
<head>
<title>构造器</title>
</head>
<body>
<script type="text/javascript">
var win=window.open('http://www.baidu.com','wroxWindow','height=400,width=400,top=10,left=10,resizeable=yes');
win.resizeTo(500,500);
win.moveTo(100,100);
win.close();
</script>
</body>
</html>
延时操作和间歇操作
JavaScript是单线程语言
// 延时执行
var delayTask = setTimeout(function(){
alert("I delay 2 seconde!");
},2000);
clearTimeout(delayTask);
// 间歇执行
setInterval(function(){
console.log('hehe');
},1000);
对话框
- confirm(msg)
- alert(msg)
- print()打印
if(confirm('are you ok?')) {
alert('i am ok');
}else{
print();//显示打印窗口
}
location对象
replace
reload
assign
href
跳转到地址栏:
``` stylus
//调用方法设置地址
location.assign('http://www.baidu.com');
//修改属性设置地址
location.href='http://www.baidu.com';
setTimeout(function(){
location.replace('http://www.sina.com');
},2000);
setTimeout(function(){
location.reload(true);//重新从服务器加载
},5000);
<div class="se-preview-section-delimiter"></div>
navigator 导航栏
检测插件
// navigator
(function (){
for (var i = 0; i < navigator.plugins.length; i++) {
console.log(navigator.plugins[i].name);
}
})();
Widevine Content Decryption Module
Shockwave Flash
Chrome PDF Viewer
Native Client
Chrome PDF Viewer
screen对象
与窗口对象不同,screen获取的是浏览器外显示器(屏幕)的信息
alert(screen.height+'height\n'+screen.width+'width');
<div class="se-preview-section-delimiter"></div>
768 height
1366 width
还有很多其他属性,可以查看文档
history对象
很明显与窗口页面有关,可以控制页面跳转
history.back();
history.forward();
history.go(2);//前进两页
history.go(-1);//后退一页