87,910
社区成员
发帖
与我相关
我的任务
分享
function OpenTopWindow(url, title, iwidth, iheight, icon) {
//计算弹窗位置
var iframeWidth = $(this).width();
var iframeHeight = $(this).height();
var setWidth = (iframeWidth - iwidth) / 2;
var setHeight = (iframeHeight - iheight) / 2;
title = title == undefined ? ' ' : title;
iwidth = iwidth == undefined ? 800 : iwidth;
iheight = iheight == undefined ? 300 : iheight;
if (url != undefined) {
var content = '<iframe name="windowIframe" src="' + url + '" width="100%" height="99%" frameborder="0"></iframe>';
var boarddiv = '<div id="Pagewindow" title="' + title + '" ></div>'//style="overflow:hidden;"可以去掉滚动条
$(document.body).append(boarddiv);
var win = $("#Pagewindow").window({
title: title,
iconCls: icon,
content: content,
width: iwidth,
height: iheight,
left: setWidth, //弹窗左边距
top: setHeight, //弹窗上边距
minimizable: false,
modal: true,
onMove: function (left, top) { // popwindow拖动时触发,限制弹出框拖动范围
var parentObj = $(this).panel('panel').parent();
var width = $(this).panel('options').width;
var height = $(this).panel('options').height;
var parentWidth = $("body").width();
var parentHeight = $("body").height();
var scrollLeft = document.body.scrollLeft;
var scrollTop = document.body.scrollTop;
// 当弹出框尺寸大于浏览器大小时,弹出框自动缩小为浏览器当前尺寸
if (width > parentWidth)
$(this).window('resize', {
width: parentWidth - 1
});
if (height > parentHeight)
$(this).window('resize', {
height: parentHeight - 1
});
// 当弹出框被拖动到浏览器外时,将弹出框定位至浏览器边缘
if (left < scrollLeft) {
$(this).window('move', {
left: scrollLeft
});
}
if (top < scrollTop) {
$(this).window('move', {
top: scrollTop
});
}
if (left > scrollLeft && left > parentWidth - width + scrollLeft) {
$(this).window('move', {
left: parentWidth - width + scrollLeft
});
}
if (top > scrollTop && top > parentHeight - height + scrollTop) {
$(this).window('move', {
top: parentHeight - height + scrollTop
});
}
}
});
}
win.window("open");
}
这个JS方法我是写在框架主页Index里的,因为我项目所有的弹窗需要在框架之上,所以所有的页面弹出都是调用这个js方法