六,BOM
1, window:浏览器窗口对象
代表一个窗口的根,所有的全局方法和属性都属于window,包括document,navigator,screen,location,history。
由于window是根,所以在javascript中可以省略,直接调用方法和属性,如document.getElementById()。
1> 简单属性
a> 画布大小(去除任务栏)
var w=window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var h=window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
window.open() // 打开新窗口
window.close() // 关闭当前窗口
window.moveTo() // 移动当前窗口
window.resizeTo() // 调整当前窗口的尺寸
c> 全局方法:
定时:setTimeout("methodName", interval);
取消定时:clearTimeout(timerVar);
定时刷界面例子:
<html>
<head>
<script type="text/javascript">
var t
function start()
{
callCartoon();
t=setTimeout("start()",1000);
}
function stop()
{
clearTimeout(t);
}
function callCartoon()
{
document.getElementById("canvas").innerHTML = document.getElementById("canvas").innerHTML+"haha<br/>";
}
</script>
</head>
<body>
<input type="button" value="start" onClick="start()">
<input type="button" value="stop" onClick="stop()">
<div id="canvas"></div>
</body>
</html>
a> screen:屏幕
整个浏览器占屏幕大小
screen.availWidth
screen.availHeight
b> location:URL
location.href \\完整url
location.protocol \\通信协议
location.hostname \\主机域名
location.pathname \\文件路径
location.port \\服务端口
c> history:历史
history.back(); //上一页
history.forward(); //下一页
d> navigator:浏览器