window.open()各参数详解
基本语法:
window.open('http://****/');
window.open()各参数详解:
window.open('http://***/', '_blank', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')
‘http:
//*****/’ :弹出窗口的地址;
‘
_blank ’:
在新窗口打开链接;或 ‘_self’在当前窗口打开链接;或 ‘_parent’在父窗口打开链接;或 ‘_top’在顶级窗口打开链接;或‘framename’在指定的框架中打开链接
height=100 : 窗口高度;
width=400 : 窗口宽度;
top=0 : 窗口距离屏幕上方的象素值;
left=0 : 窗口距离屏幕左侧的象素值;
toolbar=no : 是否显示工具栏,yes为显示;
menubar,scrollbars : 表示菜单栏和滚动栏。
resizable=no : 是否允许改变窗口大小,yes为允许;
location=no : 是否显示地址栏,yes为允许;
status=no : 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
弹出窗口居中方法:
function openWin(url,name,iWidth,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 + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no'); }
关闭弹出窗口:
window.opener = null; window.open('', '_self'); window.close();
新窗口中关闭代码如下:
<input type="button" onclick="window.opener = null; window.open('', '_self'); window.close();" value="关闭" />