Reputation: 855
Is there a way to capture event where a user clicks toggle fullscreen view button on the map?
Upvotes: 1
Views: 2765
Reputation: 855
Here is the solution which worked for me:
const onFullScreen = (cb) => {
const eventNames = [
'fullscreenchange',
'webkitfullscreenchange',
'mozfullscreenchange'
];
eventNames.map(e => document.addEventListener(e, (event) => {
const isFullScreen = document['fullScreen'] ||
document['mozFullScreen'] || document['webkitIsFullScreen'];
return cb({ isFullScreen, event });
}));
};
Upvotes: 0
Reputation: 1777
You can use HTML5 Fullscreen API which has the fullscreenchange event:
"When fullscreen mode is successfully engaged, the document which contains the element receives a fullscreenchange event. When fullscreen mode is exited, the document again receives a fullscreenchange event".
Please note All browsers implement this APIs. Nevertheless some implement it with prefixed names with slightly different spelling; e.g., instead of requestFullscreen()
, there is MozRequestFullScreen()
.
Upvotes: 3