如何让google chrome在Angular 4应用程序中全屏运行?
我正在开发一个应用程序,我想实现这样一个功能,如果用户离开一个组件进入另一个组件,那么在另一个组件的ngOnInit方法中,chrome浏览器应该全屏显示,就像我们按下Fn+F11键一样如何让google chrome在Angular 4应用程序中全屏运行?,angular,typescript,google-chrome,angular6,Angular,Typescript,Google Chrome,Angular6,我正在开发一个应用程序,我想实现这样一个功能,如果用户离开一个组件进入另一个组件,那么在另一个组件的ngOnInit方法中,chrome浏览器应该全屏显示,就像我们按下Fn+F11键一样 非常感谢您提供的任何帮助或参考。您可以尝试使用requestFullscreen 我已经在 fullScreen() { let elem = document.documentElement; let methodToBeInvoked = elem.requestFullscreen ||
非常感谢您提供的任何帮助或参考。您可以尝试使用
requestFullscreen
我已经在
fullScreen() {
let elem = document.documentElement;
let methodToBeInvoked = elem.requestFullscreen ||
elem.webkitRequestFullScreen || elem['mozRequestFullscreen']
||
elem['msRequestFullscreen'];
if (methodToBeInvoked) methodToBeInvoked.call(elem);
}
如何-全屏-
这是目前做这件事的“角度方法”
HTML
<h2 (click)="openFullscreen()">open</h2>
<h2 (click)="closeFullscreen()">close</h2>
将以下代码放在要触发的组件顶部(在@component之前):
interface FsDocument extends HTMLDocument {
mozFullScreenElement?: Element;
msFullscreenElement?: Element;
msExitFullscreen?: () => void;
mozCancelFullScreen?: () => void;
}
export function isFullScreen(): boolean {
const fsDoc = <FsDocument> document;
return !!(fsDoc.fullscreenElement || fsDoc.mozFullScreenElement || fsDoc.webkitFullscreenElement || fsDoc.msFullscreenElement);
}
interface FsDocumentElement extends HTMLElement {
msRequestFullscreen?: () => void;
mozRequestFullScreen?: () => void;
}
export function toggleFullScreen(): void {
const fsDoc = <FsDocument> document;
if (!isFullScreen()) {
const fsDocElem = <FsDocumentElement> 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();
}
这是当前的“角度方式”。
fullScreen() {
let elem = document.documentElement;
let methodToBeInvoked = elem.requestFullscreen ||
elem.webkitRequestFullScreen || elem['mozRequestFullscreen']
||
elem['msRequestFullscreen'];
if (methodToBeInvoked) methodToBeInvoked.call(elem);
}
HTML:
在Html中使用此选项:
(click)="openFullscreen()
恩戈尼特:
this.elem = document.documentElement;
TS:
把这个功能,它会工作
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();
}`]`
}尝试Brother它给了我这个错误->属性“mozRequestFullScreen”在类型“HTMLElementSure I want”上不存在当我从一个组件转到另一个组件时,它应该会自动触发Brother这工作正常,但用户需要按“I want to automatic”,所以我只是直接从ngOnInit调用了您的函数,现在它是显示此错误->未能在“元素”上执行“requestFullscreen”:只能通过用户手势启动API。不能强制网站以全屏模式显示。如果可能的话,想象一下安全问题。恶意网站可能会“劫持”一个不太懂电脑的人的桌面,从事各种可疑的业务。所有JS fullscreen api都会抛出这样一个错误:“未能在‘元素’上执行‘requestFullScreen’:api只能由用户手势启动。”如果您尝试从代码中调用它。@KrishnaRathore我试图将脚本放入ngOnInit中。它不起作用。你能帮我。。。提前感谢…可能重复抛出错误->core.js:1598错误:未捕获(承诺中):错误:模块“DashboardDefaultModule”声明的意外值“DashboardDefaultComponent”。请添加@Pipe/@Directive/@Component注释。我正在使用此注释,但在angular 7.0.0中,此注释停止工作,现在将抛出错误。
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();
}`]`