如何将弹出窗口居中? [英] How to center a popup window?
本文介绍了如何将弹出窗口居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在屏幕上显示一个弹出窗口?这些不起作用Chrome w / multimonitor。 屏幕似乎指的是整个桌面,而不仅仅是当前窗口。我想将弹出窗口置于浏览器中心。我怎样才能做到这一点?需要跨浏览器。
Center a popup window on screen? these don't work in Chrome w/ multimonitor. The "screen" seems to refer to the entire desktop, not just the current window. I want to center the popup window within the browser. How can I do that? Needs to be cross-browser.
推荐答案
这是我的方法(需要jQuery):
Here's my method (requires jQuery):
function OpenWindow(params, width, height, name) {
var screenLeft=0, screenTop=0;
if(!name) name = 'MyWindow';
if(!width) width = 600;
if(!height) height = 600;
var defaultParams = { }
if(typeof window.screenLeft !== 'undefined') {
screenLeft = window.screenLeft;
screenTop = window.screenTop;
} else if(typeof window.screenX !== 'undefined') {
screenLeft = window.screenX;
screenTop = window.screenY;
}
var features_dict = {
toolbar: 'no',
location: 'no',
directories: 'no',
left: screenLeft + ($(window).width() - width) / 2,
top: screenTop + ($(window).height() - height) / 2,
status: 'yes',
menubar: 'no',
scrollbars: 'yes',
resizable: 'no',
width: width,
height: height
};
features_arr = [];
for(var k in features_dict) {
features_arr.push(k+'='+features_dict[k]);
}
features_str = features_arr.join(',')
var qs = '?'+$.param($.extend({}, defaultParams, params));
var win = window.open(qs, name, features_str);
win.focus();
return false;
}
似乎适用于所有浏览器。
Seems to work in all browsers.
这篇关于如何将弹出窗口居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文