如何让JS弹出的窗口居中

JavaScript013

如何让JS弹出的窗口居中,第1张

<script type="text/javascript">

function openwindow(url,name,iWidth,iHeight)

{

var url//转向网页的地址

var name//网页名称,可为空

var iWidth//弹出窗口的宽度

var iHeight//弹出窗口的高度

//window.screen.height获得屏幕的高,window.screen.width获得屏幕的宽

var iTop = (window.screen.height-30-iHeight)/2//获得窗口的垂直位置

var iLeft = (window.screen.width-10-iWidth)/2//获得窗口的水平位置

window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no')

}

</script>

手打加亲测 希望对你有用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html >

<style>

#test_f{

position:relative

width:250px

margin:0 auto

}

}

#test{

width:250px

top:250px

position:absolute

background:blue

}

</style>

<script>

function show(){

if(document.getElementById("test").style.display=='none') {

document.getElementById("test").style.display=""

document.getElementById("btn").value="点击隐藏"

}else{

document.getElementById("test").style.display="none"

document.getElementById("btn").value="点击显示"

}

}

</script>

<body >

<input type="button" onclick="show()" value="点击显示" id="btn" />

<div id="test_f" >

<div id="test" style="display:none">

我在中间

</div>

<div>

</body>

</html>