我所做的是使用FancyBox 将内容加载到 iFrame 中,例如,我可以在一个简单页面中选择,然后打开 fancybox 来加载该页面。
SetupDialogBox: function (openerClientID, width, height, effect, showCloseButton, buttonsOn, offsetHeight, onStartHandler, onCompleteHandler, onClosedHandler, refreshParentOnClose) {
if (effect == null) effect = 'none';
if (width == null) width = 620;
if (height == null) height = 680;
if (buttonsOn == null) buttonsOn = false;
if (showCloseButton == null) showCloseButton = true;
if (refreshParentOnClose == null) refreshParentOnClose = false;
if (offsetHeight == null) {
// adjust for hight for offset based on apperence of buttons
if (buttonsOn) {
offsetHeight = 180;
}
else {
offsetHeight = 140;
}
}
var adjustedHeight = height - offsetHeight;
var onStartLocal = function () {
// If you want to show a loading panel, heres a good place to do it
};
var onCompleteLocal = function () {
$('#fancybox-frame').hide();
// If you want to hide load panel heres a good place to do it
a$('#fancybox-frame').contents().find('.modalContent').css('height', height - offsetHeight + 'px'); $('#fancybox-frame').fadeIn(2000); };
$('#fancybox-frame').bind('load', function () { $('#fancybox-frame').contents().find('.modalContent').css('height', adjustedHeight + 'px'); $('#fancybox-frame').fadeIn(2000); });
};
var onClosedLocal = function () { if(refreshParentOnClose) { parent.location.reload(true); } };
$('#' + openerClientID).fancybox({
'width': width,
'height': height,
'autoScale': false,
'transitionIn': effect,
'transitionOut': effect,
'padding': 0,
'scrolling': 'no',
'centerOnScroll': false,
'hideOnOverlayClick': false,
'showCloseButton': showCloseButton,
'type': 'iframe',
'onStart': function () { onStartLocal(); if (onStartHandler != null && typeof (onStartHandler) != 'undefined') onStartHandler(); },
'onComplete': function () { onCompleteLocal(); if (onCompleteHandler != null && typeof (onCompleteHandler) != 'undefined') onCompleteHandler(); },
'onClosed': function () { onClosedLocal(); if (onClosedHandler != null && typeof (onClosedHandler) != 'undefined') onClosedHandler(); }
});
},
然后我们在每个页面上插入一个链接,它是fancybox框架的处理程序
<a class="menu" href="http://www.whateverurl.com/myBox.aspx" id="menuLauncher" style="display:none;"> </a>
触发 Javascript 调用来设置盒子
SetupDialogBox('menuLauncher', 820, 360, 'fade', false, null, null, null, null);
最后是一个调用,点击时打开框(如果它在页面上)
$("#menuLauncher").trigger('click');
或者,您可以让 menuLauncher 可见并将其用作打开链接。