Installations
npm install es-screenfull
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
10.9.0
NPM Version
6.2.0
Score
68.8
Supply Chain
98.2
Quality
77.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Developer
cd-fez
Download Statistics
Total Downloads
4,407
Last Day
2
Last Week
6
Last Month
18
Last Year
295
GitHub Statistics
2 Commits
4 Watching
1 Branches
1 Contributors
Package Meta Information
Latest Version
3.0.2-patch
Package Id
es-screenfull@3.0.2-patch
Unpacked Size
11.35 kB
Size
4.45 kB
File Count
5
NPM Version
6.2.0
Node Version
10.9.0
Total Downloads
Cumulative downloads
Total Downloads
4,407
Last day
0%
2
Compared to previous day
Last week
-14.3%
6
Compared to previous week
Last month
125%
18
Compared to previous month
Last year
-19.8%
295
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
5
es-screenfull
Simple wrapper for cross-browser usage of the JavaScript Fullscreen API, which lets you bring the page or any element into fullscreen. Smoothens out the browser implementation differences, so you don't have to.
🔥 Want to strengthen your core JavaScript skills and master ES6?
I would personally recommend this awesome ES6 course by Wes Bos.
Demo
Check out my other projects
Install
Only 0.7 kB gzipped.
Download the production version or the development version.
$ npm install --save screenfull
Also available on cdnjs.
Why?
Screenfull
1if (screenfull.enabled) { 2 screenfull.request(); 3}
Vanilla JavaScript
1document.fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.documentElement.webkitRequestFullScreen; 2 3function requestFullscreen(element) { 4 if (element.requestFullscreen) { 5 element.requestFullscreen(); 6 } else if (element.mozRequestFullScreen) { 7 element.mozRequestFullScreen(); 8 } else if (element.webkitRequestFullScreen) { 9 element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); 10 } 11} 12 13if (document.fullscreenEnabled) { 14 requestFullscreen(document.documentElement); 15} 16 17// Actually it's more if you want it to work in Safari, but let's not go there...
Support
Safari doesn't support use of the keyboard in fullscreen.
Documentation
Examples
Fullscreen the page
1document.getElementById('button').addEventListener('click', () => { 2 if (screenfull.enabled) { 3 screenfull.request(); 4 } else { 5 // Ignore or do something else 6 } 7});
Fullscreen an element
1const elem = document.getElementById('target'); 2 3document.getElementById('button').addEventListener('click', () => { 4 if (screenfull.enabled) { 5 screenfull.request(elem); 6 } 7});
Fullscreen an element with jQuery
1const target = $('#target')[0]; // Get DOM element from jQuery collection 2 3$('#button').on('click', () => { 4 if (screenfull.enabled) { 5 screenfull.request(target); 6 } 7});
Toggle fullscreen on a image with jQuery
1$('img').on('click', event => { 2 if (screenfull.enabled) { 3 screenfull.toggle(event.target); 4 } 5});
Detect fullscreen change
1if (screenfull.enabled) { 2 document.addEventListener(screenfull.raw.fullscreenchange, () => { 3 console.log('Am I fullscreen? ' + (screenfull.isFullscreen ? 'Yes' : 'No')); 4 }); 5}
Detect fullscreen error
1if (screenfull.enabled) {
2 document.addEventListener(screenfull.raw.fullscreenerror, event => {
3 console.error('Failed to enable fullscreen', event);
4 });
5}
See the demo for more examples, and view the source.
Fullscreen an element with Angular.js
You can use the Angular.js binding to do something like:
1<div ngsf-fullscreen> 2 <p>This is a fullscreen element</p> 3 <button ngsf-toggle-fullscreen>Toggle fullscreen</button> 4</div>
Methods
.request()
Make an element fullscreen.
Accepts a DOM element. Default is <html>
. If called with another element than the currently active, it will switch to that if it's a decendant.
If your page is inside an <iframe>
you will need to add a allowfullscreen
attribute (+ webkitallowfullscreen
and mozallowfullscreen
).
Keep in mind that the browser will only enter fullscreen when initiated by user events like click, touch, key.
.exit()
Brings you out of fullscreen.
.toggle()
Requests fullscreen if not active, otherwise exits.
Properties
.isFullscreen
Returns a boolean whether fullscreen is active.
.element
Returns the element currently in fullscreen, otherwise null
.
.enabled
Returns a boolean whether you are allowed to enter fullscreen. If your page is inside an <iframe>
you will need to add a allowfullscreen
attribute (+ webkitallowfullscreen
and mozallowfullscreen
).
.raw
Exposes the raw properties (prefixed if needed) used internally: requestFullscreen
, exitFullscreen
, fullscreenElement
, fullscreenEnabled
, fullscreenchange
, fullscreenerror
1$(document).on(screenfull.raw.fullscreenchange, () => { 2 console.log('Fullscreen change'); 3});
FAQ
How can I navigate to a new page when fullscreen?
That's not supported by browsers for security reasons. There is, however, a dirty workaround. Create a seamless iframe that fills the screen and navigate to the page in that instead.
1$('#new-page-btn').click(() => { 2 const iframe = document.createElement('iframe') 3 4 iframe.setAttribute('id', 'external-iframe'); 5 iframe.setAttribute('src', 'http://new-page-website.com'); 6 iframe.setAttribute('frameborder', 'no'); 7 iframe.style.position = 'absolute'; 8 iframe.style.top = '0'; 9 iframe.style.right = '0'; 10 iframe.style.bottom = '0'; 11 iframe.style.left = '0'; 12 iframe.style.width = '100%'; 13 iframe.style.height = '100%'; 14 15 $(document.body).prepend(iframe); 16 document.body.style.overflow = 'hidden'; 17});
Resources
- Using the Fullscreen API in web browsers
- MDN - Fullscreen API
- W3C Fullscreen spec
- Building an amazing fullscreen mobile experience
License
MIT © Sindre Sorhus
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More