megapixel23
megapixel23

Reputation: 855

"Toggle fullscreen view" event for Google Maps

Is there a way to capture event where a user clicks toggle fullscreen view button on the map? toggle full screen view

Upvotes: 1

Views: 2765

Answers (2)

megapixel23
megapixel23

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

kemotoe
kemotoe

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

Related Questions