如何在页面加载时在单独的全屏窗口中打开网页

How to open the webpage in a separate full screen window on page load?

本文关键字:窗口 网页 单独 加载      更新时间:2023-09-26

我试图在页面加载时在全屏窗口打开网页(正如大多数银行网站一样)。我可以在点击链接时这样做,但是当我将它保持在onload函数中时,它就会进入无限循环。

以下是我所做的

<html>
<body>
<ul>
<li><a class="sprite_stumbleupon" href="#"  onclick="return windowpop()">Link</a>
</li>
</ul>
<script>
 function windowpop() {
 var leftPosition, topPosition;
 //Allow for borders.
 leftPosition =  10;
 //Allow for title and status bars.
 topPosition = 50;
 //Open the window.
 window.open(window.location.href, "Window2", "status=no,height=" + 
 screen.height + ",width=" + screen.width + ",resizable=yes,left=" + 
 leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",
 screenY=" +    topPosition +",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
 }
 </script>
 </body>
 </html>

当我点击url时,上面的代码工作正常。我想要的是在加载页面时执行相同的功能,所以我在onload内部body标签中调用了windowpop()函数。然后继续加载新窗口。不知道如何只加载一次新窗口。非常感谢任何帮助。

似乎您正在声明调整大小的窗口的名称为Window2。也许你可以利用它,加上if语句:

if(window.name != 'Window2'){
    window.open(...);
}else{
    alert("This is fullscreen!");
}

应该只以全屏模式打开窗口一次。