最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Window.popup in center align in browser - Stack Overflow

programmeradmin5浏览0评论

I have a Div data which is ing 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 ing 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 --

/

Please help me out !! or any guidance.

I have a Div data which is ing 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 ing 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/Wj3Qk/2/

Please help me out !! or any guidance.

Share Improve this question edited Sep 24, 2013 at 9:57 FrontEnd Expert asked Sep 24, 2013 at 9:07 FrontEnd ExpertFrontEnd Expert 5,81310 gold badges63 silver badges100 bronze badges 1
  • possible duplicate of How to center a popup window? – epascarello Commented Sep 24, 2013 at 9:16
Add a ment  | 

2 Answers 2

Reset to default 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");
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+');
发布评论

评论列表(0)

  1. 暂无评论