问题
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