2

I have a Div data which is coming dynamically. I want to open that div data in popup after some event fired. I am done with my code. But when popup is opening in my browser its not centered aligned.. Its coming in corner..

My code :-

        var w  = 620;
        var h = 360;
        var left = (screen.width/2)-(w/2);
        var top = (screen.height/2)-(h/2);
        var divText = document.getElementById("inviteConfirmationMessage").outerHTML;
        var myWindow = window.open('','','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
        var doc = myWindow.document;
        doc.open();
        doc.write(divText);
        doc.close();

Working in Mozilla firefox but not working in Chrome --

http://jsfiddle.net/Wj3Qk/2/

Please help me out !! or any guidance.

Javascript Coder
  • 5,691
  • 8
  • 52
  • 98
  • possible duplicate of [How to center a popup window?](http://stackoverflow.com/questions/5681415/how-to-center-a-popup-window) – epascarello Sep 24 '13 at 09:16

2 Answers2

4
    var left = (window.screen.width / 2) - ((w / 2) + 10);
    var top = (window.screen.height / 2) - ((h / 2) + 50);

window.open('','',
    "status=no,height=" + height + ",width=" + width + ",resizable=yes,left="
    + left + ",top=" + top + ",screenX=" + left + ",screenY="
    + top + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
Ankit Agrawal
  • 6,034
  • 6
  • 25
  • 49
  • Thanks for your help. But its not working.. I checked.. My pop is opening in corner with same height and width – Javascript Coder Sep 24 '13 at 09:16
  • Neeraj i use this code and it open popup in center – Ankit Agrawal Sep 24 '13 at 09:20
-2
var myWindow = window.open('','','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);

you are missing last quote in it.

Is should be like this :

var myWindow = window.open('','','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left+');
Ganesh Pandhere
  • 1,612
  • 8
  • 11