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

前端 未结 3 1770
小鲜肉
小鲜肉 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:28

    How To - Fullscreen - https://www.w3schools.com/howto/howto_js_fullscreen.asp

    This is the current "angular way" to do it.

    HTML

    open

    close

    Component

    import { DOCUMENT } from '@angular/common';
    import { Component, Inject, OnInit } from '@angular/core';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.scss']
    })
    export class AppComponent implements OnInit {
      constructor(@Inject(DOCUMENT) private document: any) {}
      elem;
    
      ngOnInit() {
        this.elem = document.documentElement;
      }
    
      openFullscreen() {
        if (this.elem.requestFullscreen) {
          this.elem.requestFullscreen();
        } else if (this.elem.mozRequestFullScreen) {
          /* Firefox */
          this.elem.mozRequestFullScreen();
        } else if (this.elem.webkitRequestFullscreen) {
          /* Chrome, Safari and Opera */
          this.elem.webkitRequestFullscreen();
        } else if (this.elem.msRequestFullscreen) {
          /* IE/Edge */
          this.elem.msRequestFullscreen();
        }
      }
    
      /* Close fullscreen */
      closeFullscreen() {
        if (this.document.exitFullscreen) {
          this.document.exitFullscreen();
        } else if (this.document.mozCancelFullScreen) {
          /* Firefox */
          this.document.mozCancelFullScreen();
        } else if (this.document.webkitExitFullscreen) {
          /* Chrome, Safari and Opera */
          this.document.webkitExitFullscreen();
        } else if (this.document.msExitFullscreen) {
          /* IE/Edge */
          this.document.msExitFullscreen();
        }
      }
    }
    

提交回复
热议问题