San*_*osh 1 javascript window.open
我有一个按钮单击,使用 javascript window.open 打开一个弹出窗口。
我的代码如下所示:
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
window.open('', '', 'height=5,width=5');
}
</script>
Run Code Online (Sandbox Code Playgroud)
现在弹出窗口在屏幕的左上角打开。如何设置弹出窗口,使其在右下角打开,以便用户不知道弹出窗口已打开?
提前致谢
如果您的意思是(窗口大小)-(弹出窗口大小),它将是这样的:
<script>
function myFunction() {
height=5;
width=5;
t=window.innerHeight-height
l=window.innerWidth-width
window.open('', '', 'height='+height+', width='+width+', left='+l+', top='+t );
Run Code Online (Sandbox Code Playgroud)
}
其中: - t = 底部 - 弹出高度 - l = 右侧 - 弹出宽度
请注意,此示例适用于 Chrome/Firefox/... IE 使用不同的语法来检索窗口大小值