`
xuantian868
  • 浏览: 30415 次
  • 性别: Icon_minigender_1
  • 来自: 济南
最近访客 更多访客>>
社区版块
存档分类
最新评论

onresize,opener,self

阅读更多
onresize的触发是这样的:按照一个很短的间隔来判断,当你把200*200的窗口拖到200*400的时候中间要经过几次resize,从而触发几个onresize.  
  要避免多次onresize触发引起某个代码执行多次的不良后果,可以自己写个函数,在onresize之后间隔一个时间值(setTimeout)再调用你要执行的代码,通过置状态变量判断是否要执行,如果两次onresize的时间间隔小于100ms,就再setTimeout,等等看。

如何解决window.onresize的多次调用?
<script type="text/javascript">
var  resizeTimer = null;
function doResize(){
  alert("width="+document.documentElement.clientWidth + "   Height="+document.documentElement.clientHeight);resizeTimer=null
}
window.onresize = function(){
   if(resizeTimer==null){
  resizeTimer = setTimeout("doResize()",300);
}
}
</script>


opener:对打开当前窗口的window对象的引用,如果当前窗口被用户打开,则它的值为null.

self:自引用属性,是对当前window对象的应用,与window属性同义.

self代表自身窗口,opener代表打开自身的那个窗口,比如窗口A打开窗口B.如果靠window.open方法,则对于窗口B,self代表B自己,而opener代表窗口A.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics