简体   繁体   English

iPhone / iOS 6 / Mobile Safari:有没有办法检测“浏览器全屏”模式? Android兼容性?

[英]iPhone/iOS 6/Mobile Safari: Is there a way to detect “in browser fullscreen” mode? Android compatibility?

I am wondering how it is possible to detect if a user uses the "fullscreen feature" in Safari. 我想知道如何检测用户是否在Safari中使用“全屏功能”。 I don't mean if it's started from the springboard, I mean the feature that was added in iOS 6. 我的意思不是说它是从跳板开始的,而是我在iOS 6中添加的功能。

Actually, there was a similar question here on SO where this code was posted: 实际上,SO上有一个类似的问题,此代码已发布在哪里:

$(window).on('resize', function(){
    if ($(this).height() > 300 && 
       (window.orientation == 90 || window.orientation == -90)) {
        // Full screen!
    } else {
        // Exit full screen!
    }
});

But the problem with it is that it is also triggered when the orientation is changed. 但是它的问题是,当方向改变时也会触发它。 Also, I am not sure if it is a good idea to use hardcoded values, especially "300"? 另外,我不确定使用硬编码值(尤其是“ 300”)是否是个好主意? Is there a better way to detect "in browser fullscreen" mode? 有没有更好的方法来检测“以浏览器全屏显示”模式?

Edit: Ok so I just checked: When changing the direction on an iPhone, onorientationchange and the resize event is triggered. 编辑:好的,所以我刚刚检查:在iPhone上更改方向时,会触发onorientationchange resize事件。 Changing Safari to fullscreen also triggers resize - so I could hook my function to that event. 将Safari更改为全屏模式也会触发resize -因此我可以将函数挂接到该事件。 But how about Android devices, do they also trigger resize ? 但是Android设备如何,它们也会触发resize吗? Or is it best to simply bind functions to onorientationchange and resize ? 还是最好只将函数绑定到onorientationchange resize

Cross browser way 跨浏览器方式

$(document,window).on('resize orientationchange webkitfullscreenchange mozfullscreenchange fullscreenchange',  function(){

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM