Is there a way to centre a pop up window called from Javascript instead of having it pop up where it fancies?
Printable View
Is there a way to centre a pop up window called from Javascript instead of having it pop up where it fancies?
Here's an example:
h is the height you want the window to be, w is the width.Code:<script type="text/javascript">
var h = 500;
var w = 500;
var l = (screen.width - w) / 2;
var t = (screen.height - h) / 2;
window.open('about:blank', 'blank', 'width='+w+', height='+h+', top='+t+', left='+l);
</script>
It then calculates what the top and left needs to be for it to be centered and opens the window.