Skip to content Skip to sidebar Skip to footer

Javascript : Open Popup In The Center Of The Screen (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;

Solution 1:

I see the below code is working fine.

<script>functionpopupCenter(url, title, w, h) {
      var left = (screen.width/2)-(w/2);
      var top = (screen.height/2)-(h/2);
      returnwindow.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.com', 'myPop1',450,450);" href="javascript:void(0);">CLICK TO OPEN POPUP</a>

You can see details here

Solution 2:

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.com/a/5078596/2762516

Post a Comment for "Javascript : Open Popup In The Center Of The Screen (chrome)"