admin管理员组文章数量:1400579
i am using this code to open a popup in the center of the screen
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, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left + ', screenX=' + left + ', screenY=' + top);
}
All works fine in Firefox, IE and Safari but in Chrome the popup shows up randomly. How can i make this works also in Chrome?
i am using this code to open a popup in the center of the screen
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, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left + ', screenX=' + left + ', screenY=' + top);
}
All works fine in Firefox, IE and Safari but in Chrome the popup shows up randomly. How can i make this works also in Chrome?
Share Improve this question asked Oct 4, 2013 at 10:50 Alberto PellizzonAlberto Pellizzon 6091 gold badge8 silver badges23 bronze badges2 Answers
Reset to default 2I see the below code is working fine.
<script>
function popupCenter(url, title, w, h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>
The Link Sample:
<a onclick="popupCenter('http://www.nigraphic.', 'myPop1',450,450);" href="javascript:void(0);">CLICK TO OPEN POPUP</a>
You can see details here
This is happening because your zoom level is not 100% in Chrome. If the zoom level is off, it changes how it gets the coordinates. In other browser, at least IE, the zoom factor does not change where the window is opened. So correct it by checking the zoom, and that will fix your problem using the given function you provided earlier while in Chrome.
also, here is a good post about checking browser zoom levels: https://stackoverflow./a/5078596/2762516
本文标签: Javascriptopen popup in the center of the screen (Chrome)Stack Overflow
版权声明:本文标题:Javascript : open popup in the center of the screen (Chrome) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744269312a2598103.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论