1

我有在它的IFRAME网页(我不喜欢它,但这是它是的方式)。这不是一个跨域的iframe,所以没有什么可担心的。帮我重新中心ModalPopup一个iframe中时iframe的父窗口滚动

我已经写一个jQuery延伸,做了ModalPopup的基于的IFRAME父级的宽度和高度的定心(其是从重写AjaxControlToolkit.ModalPopupBehavior._layout方法调用),以便它看起来甚至居中尽管iframe不在页面的中心。这是一个很大的棘手的问题,特别是因为该网页我加入了iframe来运行怪癖模式。

现在,我也重写AjaxControlToolkit.ModalPopupBehavior._attachPopup,这样当父窗口调整大小或滚动时,ModalPopup的iframe recenter的本身相对于父窗口的新尺寸的内部。但是,重视弹出到父窗口的大小调整事件相同的代码不会对父窗口的滚动事件工作。看到下面的代码和评论:

AjaxControlToolkit.ModalPopupBehavior.prototype._attachPopup = function() { 
    /// <summary> 
    /// Attach the event handlers for the popup to the PARENT window 
    /// </summary> 
    if (this._DropShadow && !this._dropShadowBehavior) { 
     this._dropShadowBehavior = $create(AjaxControlToolkit.DropShadowBehavior, {}, null, null, this._popupElement); 
    } 
    if (this._dragHandleElement && !this._dragBehavior) { 
     this._dragBehavior = $create(AjaxControlToolkit.FloatingBehavior, {"handle" : this._dragHandleElement}, null, null, this._foregroundElement); 
    }   
    $addHandler(parent.window, 'resize', this._resizeHandler); // <== This WORKS 
    $addHandler(parent.window, 'scroll', this._scrollHandler); // <== This DOES NOT work 
    this._windowHandlersAttached = true; 
} 

任何人都可以向我解释为什么resize事件工作,而滚动事件没有?任何建议或替代方案在那里帮助我?我使用jQuery,所以如果我可以用的东西,除了从MS的$ addHandler操作方法,我不会有事的。要知道,我也有覆盖_detachPopup功能删除的处理程序,所以我需要考虑到这一点。

谢谢!

回答

1

没关系,怪癖模式又一次刺痛了我。从父项获取scrollTop位置失败,因为它的documentElement不存在。我切换

$(top.window.document.documentElement).scrollTop(); 

$(top.window.document.body).scrollTop(); 

在我的jQuery扩展围绕代码和它现在是幸福的。