日期:2014-05-16  浏览次数:20325 次

在一个jsp写的页面中,通过点击一个文字链接打开一个小窗口
在网上找来的几个方法,与大家共享

第一种方法,在指定的位置弹出小窗口:

<a onClick="window.open('Xchk.jsp','弹出小窗口','width=400,height=300,top=200,left=200')" style="cursor:hand" >弹出小窗口</a>

其中top和left是表示打开的小窗口距屏幕左上角的距离大小,但是由于各台机器显示器分辨率不同,在页面中显示的实际效果也不同。

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

现在实现无论分辨率如何,都让打开的这个小窗口始终位于屏幕中间

第二种方法,直接居中在屏幕中间:

<script>
function openWin(url,width,height){
var phxWin=window.open(url,'','width='+width+',height='+height+',left='+(screen.width-width)/2+',top='+(screen.height-height)/2+'');
}
</script>
<a onClick="openWin('Xchk.jsp',400,300)" style="cursor:hand" >弹出小窗口'</a>

第三种方法,移动式在屏幕中间:
<script>
function openWin(url,width,height){
var phxWin=window.open(url,'','width='+width+',height='+height+'');
phxWin.moveTo((screen.width-width)/2,(screen.height-height)/2)
}
</script>
<a onClick="openWin('Xchk.jsp',400,300)" style="cursor:hand" >弹出小窗口'</a>