showing new window pop up to center
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;
}
精彩评论