By
zhpooer
更新日期:
BOM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| var wroxWin = window.open("http://www.wrox.com",
"wroxWindow",
"height=400, width=400, top=10, left=10, resizable=yes")
wroxWin.resizeTo(500, 500);
wroxWin.moveTo(100, 100);
wroxWin.close();
log(wroxWin.closed);
alert(wroxWin.opener == window);
var timeoutId = setTimeout(function(){
alert();
}, 1000);
clearTimeout(timeoutId);
var intervalId = setInterval(doFunc, 500);
clearInterval(intervalId);
var b = comfirm("any");
var result = prompt("What is your name?", "")
if(result !== null){}
|
location 对象
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| log(window.location == document.location);
location.hash;
location.host;
location.hostname;
location.href;
location.pathname;
location.port;
location.protocol;
location.search;
location.assign("http://www.baidu.com")
window.location = "httt://www.baidu.com"
location.href = "http://www.baidu.com"
location.replace("");
location.reload();
location.reload(true);
|
navigator
检测插件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| function hasPlugin(name) {
name = name.toLowerCase();
for( var i=0, i< navigator.plugin.length; i++) {
if(navigator.plugin[i].name.toLowerCase().indexOf(name) > -1) {
return true
}
}
return false;
}
function hasIEPlugin(name) {
try {
new activeXObject(name);
return true;
} catch (ex) {
return false;
}
}
function hasFlash() {
var result = hasPlugin("Flash");
if (!result) {
result = hasIEPlugin("ShockwaveFlash.ShockwaveFlash");
}
return result;
}
|
Screen 对象
screen 对象基本上只用来表示客户端的能力,
其中包括浏览器窗口外部的显示器的信息, 如像素宽度和高度等.
1
| window.resizeTo(screen.availWidth, screen.availHeight)
|
history 对象
1
2
3
4
5
6
7
8
9
10
| history.go(-1);
history.go(1);
history.go(2);
history.back();
history.forward();
if(history.length == 0 ){}
history.go("wrox.com");
|
Tips
1
2
3
4
5
6
7
8
9
10
11
12
| var win = window.open('about:blank');
// 清空页面并写入
win.document.write();
win.close(); // 关闭窗口
// 可视区居中, 可以用 fixed 但是 ie6 不支持
window.onresize = window.onload = window.onscroll = function (){
var oDiv = document.getElementById('div');
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var t = (document.documentElement.clientHeight - oDiv.offsetHeight)/2;
oDiv.style.top = scrollTop + t + 'px';
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| window.onload=function () {
var oBtn=document.getElementById('btn1');
var bSys=true;
var timer=null;
window.onscroll=function () {
if(!bSys) {
clearInterval(timer);
}
bSys=false;
};
oBtn.onclick=function () {
timer=setInterval(function (){
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
var iSpeed=Math.floor(-scrollTop/8);
if(scrollTop==0) {
clearInterval(timer);
}
bSys=true;
document.documentElement.scrollTop=document.body.scrollTop=scrollTop+iSpeed;
}, 30);
};
};
|