如何退出全屏Web应用程序 [英] How to quit a full screen web app

查看:170
本文介绍了如何退出全屏Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试将我们的网络应用程序作为全屏网络应用程序运行。我使用这些元标记工作:

We are trying to get our web app to run as a full screen web app. I got this to work using these meta tags:

    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <meta name="apple-mobile-web-app-title" content="Full Screen">

所以现在当您从iPhone或Android设备上的主屏幕启动网络应用程序时,它将启动全屏(没有浏览器控件)。

So now when you launch the web app from your home screen on iPhone or android devices, it will launch into full screen (with no browser controls).

现在我们需要一种允许用户退出的方法,我希望创建一个具有退出按钮的菜单但是使用window.close()在chrome中给出了以下错误:

Now we need a way to allow the user to quit, I was hoping to create a menu that had a quit button but using window.close() gives me the following error in chrome:

Scripts may close only the windows that were opened by it.

处理此问题的正确方法是什么?

What would be the correct way to handle this?

推荐答案

关闭全屏模式的一种方法是使用以下脚本:

One way to close a full screen mode is to use the following script:

 function exitFullScreen(element) { 
        var requestMethod = element.exitFullscreen ||
                                                  element.mozCancelFullScreen || 
                                                  element.webkitExitFullscreen || 
                                                  element.msExitFullscreen; 
         if (requestMethod) { 
               requestMethod.call(element); 
         } else { 
               console.log("Oops. Request method false."); 
          } 
     }

然后将其称为:

       var $smallscreenButton = $("#smallscreen-button"); 
       $smallscreenButton.on("click", function() { 
                    var elem = document;
                    exitFullScreen(elem); 
        });

你用window.close()分阶段的错误是你应该在同一个javascript中打开窗口使用window.open()然后它应该已正确关闭。你只是不能用javascript关闭随机窗口,这就是为什么你不能先打开而不打开的原因。

The error you phased with window.close() is that you should have opened the window inside same javascript with window.open() and then it should have closed correctly. You just cannot close random windows with javascript, that's why you cannot call close without opening first.

所以,就像:

 var myWindow = window.open();
 myWindow.close(); // this works.

资料来源:

[1] < a href =https://stackoverflow.com/questions/25110166/how-can-we-programmatically-enter-and-exit-the-fullscreen-mode-in-javascript>我们如何以编程方式进入和退出全屏javascript中的模式?

[2] window.close()不起作用 - 脚本可能只关闭它打开的窗口

这篇关于如何退出全屏Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆