显示新窗口弹出中心

时间:2010-10-25 12:21:35

标签: php javascript

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

您好

我希望在点击“Hello”时将此弹出窗口显示为中心

2 个答案:

答案 0 :(得分:1)

要在中心打开,您需要使用屏幕的宽度和高度。单击时打开,只需将其绑定到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;
        }

答案 1 :(得分:0)

创建ID为“open”的HTML元素,并将此脚本嵌入到文档的头部:

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;
}