1. 程式人生 > >JS中window.open彈出視窗居中

JS中window.open彈出視窗居中

利用下面這個js函式可以使window.open彈出的視窗居中
function openwindow(url,name,iWidth,iHeight)
{
var url; //轉向網頁的地址;
var name; //網頁名稱,可為空;
var iWidth; //彈出視窗的寬度;
var iHeight; //彈出視窗的高度;
var iTop = (window.screen.availHeight-30-iHeight)/2; //獲得視窗的垂直位置;
var iLeft = (window.screen.availWidth-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');

}
<a href="javascript:void(0);" onclick="javascript:openwindow('a.html','',400,200);">轉到</a>

原帖地址:http://ehaidao.blog.163.com/blog/static/139876521201032844a34485/