当前位置: 动力学知识库 > 问答 > 编程问答 >

php - showing new window pop up to center

问题描述:

function open1() {

window.open('http://www.pageresource.com/jscript/jex5.htm','ddsfa','width=400,height=200');

}

Hello

I want show this popup to center when click on "Hello"

网友答案:

To open on center you need to use the width and the height of the screen. An to open on click just bind it on window.onload:

        function open1() {

            var left = (screen.width - 400)/2,
                top = (screen.height - 200)/2,
                settings = 'height=200,width=400,top=' + top + ',left=' + left;

            window.open('http://www.pageresource.com/jscript/jex5.htm','popUp',settings); 
        } 

        window.onload = function (){
            document.getElementById("openPopup").onclick = open1;
        }
网友答案:

Create HTML element with id "open" and embed this script into your document's head:

function open1() {

    var w = 400, // width of your block
        h = 200, // height of your block
        l = (screen.width - w)/2, // block left position
        t = (screen.height -h)/2; //block top position

    window.open('http://www.pageresource.com/jscript/jex5.htm','','height=' + h + ',width=' + w + ',top=' + t + ',left=' + l);
}

window.onload = function() {
        document.getElementByID("open").onclick = open1;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: