angular - 如何让谷歌浏览器在 Angular 4 应用程序中全屏显示?

标签 angular typescript google-chrome angular6

我正在开发一个应用程序,我想在其中实现这样的事情,如果用户离开一个组件并进入另一个组件,那么在其他组件的 ngOnInit 方法中,chrome 浏览器应该像我们按 Fn + F11 键时一样全屏显示。

感谢任何帮助或引用。

最佳答案

如何 - 全屏 - https://www.w3schools.com/howto/howto_js_fullscreen.asp

这是目前的“Angular 方式”。

HTML

<h2 (click)="openFullscreen()">open</h2>
<h2 (click)="closeFullscreen()">close</h2>

组件

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();
    }
  }
}

关于angular - 如何让谷歌浏览器在 Angular 4 应用程序中全屏显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51998594/

相关文章:

typescript - TS2322 : Type 'Observable<{}>' is not assignable to type 'Observable<Hero>'

html - 获取不正确的 offsetWidth 和 offsetHeight 值

CSS 样式不适用于已经存在的组件/主体标签

Angular 4 : Cannot read property 'http' of undefined

javascript - typescript 类型 'unknown' 不可分配给类型 'number'

python - 如何使用 ChromeOptions 使用 ChromeDriver 禁用 Python Selenium 中的 CSS

Angular 2 http.get 没有在 header 中发送 token

javascript - 尝试过的二叉树示例将输出作为一个对象,我怎样才能将这个对象值放入一个数组中以处理进一步的问题

html - 禁用浏览器添加溢出 :hidden on touch screen enabled devices

macos - 如何在 Mac 上向 Google Chrome 添加启动参数?