开发者

showing new window pop up to center

function open1() { window.open('http://www.pagere开发者_Python百科source.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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜