tags:

views:

26

answers:

3
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"

A: 

You can use the left and top parameters, and calculate them yourself so that the window would pop up in the center of the screen.

http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx

var left = (screen.width - 400) / 2;
var top = (screen.height - 200) / 2;
window.open('http://www.pageresource.com/jscript/jex5.htm', '',
    'width=400, height=200,' + 'left=' + left + ', top=' + top + ');
Dan Dumitru
+1  A: 

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;
        }
madeinstefano
A: 

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