window 对象
1 全局作用域
var age= 29 ; window.color = "red"; //IE 9 版本以下报错 delete window.age ; //false //IE 9 版本以下报错 delete window.color ; // true alert(window.age) // 29 alert(window.color) // undefined
2 iframe
window frams 中 通过索引值从0开始,从左到又,从上到下 也可以通过名称来进行访问
<frameset cols="50%,50%">
<frame src="" name="frame1">
<frame src="" name="frame2">
</frameset>
window.frames[0] = window.frames["frame1"];
window.frames[1] = window.frames["frame2"];
另外TOP 对象始终指向最高层的框架
3 窗口位置
var leftTops = (typeof window.screenLeft == 'number') ? window.screenLeft : window.screenX; var topTops = (typeof window.screenTop == 'number') ? window.screenTop : window.screenY; 因为fireFox 的位置信息是用screenX, screenY 来表示的,其他的用screenLeft,screenTop
4 窗口大小
innerWidth innerHeight outerWidth outerHeight
5 间歇调用和超时调用
//超时调用 var id = setTimeout(function(){alert(1)},1000); clearTimeout(id) //他表示的是等1S 后 讲当前任务放入到队列中,如果队列是空的,就立即执行 //否则等待 var id = setInterval(function(){},1000); cleartInterval(id); //表示每个1S 执行1次
6 系统对话框
//alert , confirm ,prompt //alert 不说 if(confirm("delete")){ alert("delete") }else{ alert("ok") } prompt("what's your name","allen"); var inputName = prompt("what's your name");
注意
javascript trim 方法在IE 9 以上才能用,因此还是建议使用jQuery的trim 方法