Center a popup window on screen?这些不工作在Chrome w / multitoritor. “屏幕”似乎是指整个桌面,而不仅仅是当前的窗口.我想将浏览器中的弹出窗口居中.我怎样才能做到这一点?需要跨浏览器
解决方法
这是一个演示(应该加载Google):
function popupwindow(url,title,w,h) { wLeft = window.screenLeft ? window.screenLeft : window.screenX; wTop = window.screenTop ? window.screenTop : window.screenY; var left = wLeft + (window.innerWidth / 2) - (w / 2); var top = wTop + (window.innerHeight / 2) - (h / 2); return window.open(url,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + w + ',height=' + h + ',top=' + top + ',left=' + left); }
<button onclick="popupwindow('http://www.google.com/','hello',400,400)"> Click </button>