65.9K
CodeProject 正在变化。 阅读更多。
Home

Javascript - 模拟浏览器全屏

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0投票)

2013 年 10 月 11 日

CPOL

1分钟阅读

viewsIcon

7336

在本文中,我们将探讨如何通过 javascript 使浏览器看起来像全屏状态。通常,由于安全问题,无法通过 javascript 触发

在本文中,我们将探讨如何通过 javascript 使浏览器看起来像全屏状态。通常,由于安全问题,无法通过 javascript 触发全屏模式(F11)。但我们可以隐藏浏览器的状态栏、工具栏、地址栏和标题栏,以模拟全屏效果。

让我们考虑一个点击按钮时将浏览器设置为全屏的场景。

1. 我们可以使用 javascript 的 `window.open` 方法在新窗口中打开当前 URL

window.open(URL,name,features,replace);

2. 现在可以通过使用可用的项目来配置 features。

params = 'width=' + screen.availWidth + ';

params += ', height=' + screen.availHeight + ';

params += ', fullscreen=yes';

params += ', status=no,titlebar=no,location=0,top=0, left=0';

window.open(window.location, "fullscreentest", params);

以下链接包含所有可用参数及其值的列表。

https://w3schools.org.cn/jsref/met_win_open.asp

3. 在点击按钮时执行此操作,我们将能够在全屏模式下查看浏览器。

完整的代码片段如下所示。

代码片段

function fullscreen() {   

            params = 'width=' + screen.availWidth;

            params += ', height=' + screen.availHeight;

            params += ', fullscreen=yes';

            params += ', status=no,titlebar=no,location=0,top=0, left=0';           

            window.open(window.location, "test", params);

        }

 

© . All rights reserved.