JavaScript之六:BOM

六,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;

 

 

b> 简单方法

 

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>

 

2> 复合属性

 

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:浏览器

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值