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

时间秒杀一切 提交于 2019-12-11 03:29:31

问题


I am wondering how it is possible to detect if a user uses the "fullscreen feature" in Safari. I don't mean if it's started from the springboard, I mean the feature that was added in iOS 6.

Actually, there was a similar question here on SO where this code was posted:

$(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"? 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. Changing Safari to fullscreen also triggers resize- so I could hook my function to that event. But how about Android devices, do they also trigger resize? Or is it best to simply bind functions to onorientationchange and resize?


回答1:


Cross browser way

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

});


来源:https://stackoverflow.com/questions/15322915/iphone-ios-6-mobile-safari-is-there-a-way-to-detect-in-browser-fullscreen-mod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!