我在主页面内有一个iframe。 iframe页面内有一个modalpopup。 当modalpopup显示时,它的父级是iframe body和主页面parent body。 因此覆盖层只覆盖了iframe而不是整个页面。
我尝试使用jQuery将modalpopup从iframe移动到父窗口的body元素(或父级body内的任何其他元素)。 我收到了无效参数错误。
如何从iframe内的页面显示modalpopup并覆盖整个文档,包括父文档?
更新:
由于一些用户对实现相同的行为感兴趣,所以这里提供一个解决方法。
我建议最好的解决方法是将modalpopup放在主页面中,然后从iframe中调用它,类似于以下内容:
/* function in the main(parent) page */
var _onMyModalPopupHide = null;
function pageLoad(){
// would be called by ScriptManager when page loads
// add the callback that will be called when the modalpopup is closed
$find('MyModalPopupBehaviorID').add_hidden(onMyModalPopupHide);
}
// will be invoked from the iframe to show the popup
function ShowMyModalPopup(callback) {
_onMyModalPopupHide = callback;
$find('MyModalPopupBehaviorID').show();
}
/* this function would be called when the modal popup is closed */
function onMyModalPopupHide(){
if (typeof(_onMyModalPopupHide) === "function") {
// fire the callback function
_onMyModalPopupHide.call(this);
}
}
/* functions in the page loaded in the iframe */
function ShowPopup(){
if(typeof(window.parent.ShowMyModalPopup) === "function") {
window.parent.ShowMyModalPopup.apply(this, [OnPopupClosed]);
}
}
// will be invoked from the parent page .. after the popup is closed
function OnPopupClosed(){
// do something after the modal popup is closed
}
希望这能帮到你