How to make google chrome go full screen in Angular 4 Application?

前端 未结 3 1762
小鲜肉
小鲜肉 2021-02-14 03:42

I am developing an application where I want to implement such a thing where if user leaves from one component & enters other component, then in other component\'s ngOnInit m

3条回答
  •  孤城傲影
    2021-02-14 04:35

    put the following code on the top of the component (before @Component) you want to trigger:

        interface FsDocument extends HTMLDocument {
          mozFullScreenElement?: Element;
          msFullscreenElement?: Element;
          msExitFullscreen?: () => void;
          mozCancelFullScreen?: () => void;
        }
    
        export function isFullScreen(): boolean {
          const fsDoc =  document;
    
          return !!(fsDoc.fullscreenElement || fsDoc.mozFullScreenElement || fsDoc.webkitFullscreenElement || fsDoc.msFullscreenElement);
        }
    
        interface FsDocumentElement extends HTMLElement {
          msRequestFullscreen?: () => void;
          mozRequestFullScreen?: () => void;
        }
    
        export function toggleFullScreen(): void {
          const fsDoc =  document;
    
          if (!isFullScreen()) {
            const fsDocElem =  document.documentElement;
    
            if (fsDocElem.requestFullscreen)
              fsDocElem.requestFullscreen();
            else if (fsDocElem.msRequestFullscreen)
              fsDocElem.msRequestFullscreen();
            else if (fsDocElem.mozRequestFullScreen)
              fsDocElem.mozRequestFullScreen();
            else if (fsDocElem.webkitRequestFullscreen)
              fsDocElem.webkitRequestFullscreen();
          }
          else if (fsDoc.exitFullscreen)
            fsDoc.exitFullscreen();
          else if (fsDoc.msExitFullscreen)
            fsDoc.msExitFullscreen();
          else if (fsDoc.mozCancelFullScreen)
            fsDoc.mozCancelFullScreen();
          else if (fsDoc.webkitExitFullscreen)
            fsDoc.webkitExitFullscreen();
        }
    
        export function setFullScreen(full: boolean): void {
          if (full !== isFullScreen())
            toggleFullScreen();
        }
    

    and on the ngOnInit method make a call to the setFullScreen(full: boolean) function:

    ngOnInit(): void {
        setFullScreen(true);
    }
    

提交回复
热议问题