I am developing an application where i need user when user logs in screen should be full (Example like : Chrome f11) & after logout return to its original postilion.
Asked
Active
Viewed 1,592 times
1
-
Possible duplicate of [How to make the window full screen with Javascript (stretching all over the screen)](https://stackoverflow.com/questions/1125084/how-to-make-the-window-full-screen-with-javascript-stretching-all-over-the-scre) – CodeCaster Aug 10 '18 at 09:56
-
1Its not duplicate buddy i need this in Angular – Jignesh Mistry Aug 10 '18 at 09:57
-
You can call JavaScript code from Angular, pal. – CodeCaster Aug 10 '18 at 09:59
-
1Can u please show it here - https://stackblitz.com/edit/angular-jfr7zf – Jignesh Mistry Aug 10 '18 at 10:00
2 Answers
2
If you dont want to add an extra library dependency, you can just implement a full-screen toggle function like this:
/**
* Toggles the fullscreen mode.
*/
toggleFullscreen() {
if (document.webkitIsFullScreen) {
this._exitFullscreen();
} else {
this._activateFullscreen();
}
}
/**
* Activate Full Screen Mode.
*/
private _activateFullscreen() {
let fullscreenElement = document.documentElement;
if (fullscreenElement.requestFullscreen) {
fullscreenElement.requestFullscreen();
} else if (fullscreenElement.mozRequestFullScreen) {
/* Firefox */
fullscreenElement.mozRequestFullScreen();
} else if (fullscreenElement.webkitRequestFullscreen) {
/* Chrome, Safari and Opera */
fullscreenElement.webkitRequestFullscreen();
} else if (fullscreenElement.msRequestFullscreen) {
/* IE/Edge */
fullscreenElement.msRequestFullscreen();
}
}
/**
* Exits Full Screen Mode.
*/
private _exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
/* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
/* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
/* IE/Edge */
document.msExitFullscreen();
}
}

FAISAL
- 33,618
- 10
- 97
- 105
1
Take a look at this library: https://github.com/sindresorhus/screenfull.js/
There's an Angular 2 Example too:
import {Directive, HostListener} from '@angular/core';
import * as screenfull from 'screenfull';
@Directive({
selector: '[toggleFullscreen]'
})
export class ToggleFullscreenDirective {
@HostListener('click') onClick() {
if (screenfull.enabled) {
screenfull.toggle();
}
}
}
And then in your markup:
<button toggleFullscreen>Toggle fullscreen<button>
Then you can act based on your events and request fullscreen, toggle it on or off based on your needs.

Agash Thamo.
- 748
- 6
- 18
-
-
Thanks :) Now i need to implement when user navigates from one page to other – Jignesh Mistry Aug 10 '18 at 10:07
-
Handle that in your components handling the navigation or the component that loads on the specific pages. You can query whether the user is in fullscreen mode or not and act accordingly. If you need more help, just give me a heads up and include your code. – Agash Thamo. Aug 10 '18 at 10:19
-