Menu
Products
Products
Video Hosting
Upload and manage your videos in a centralized video library.
Image Hosting
Upload and manage all your images in a centralized library.
Galleries
Choose from 100+templates to showcase your media in style.
Video Messaging
Record, and send personalized video messages.
CincoTube
Create your own community video hub your team, students or fans.
Pages
Create dedicated webpages to share your videos and images.
Live
Create dedicated webpages to share your videos and images.
For Developers
Video API
Build a unique video experience.
DeepUploader
Collect and store user content from anywhere with our file uploader.
Solutions
Solutions
Enterprise
Supercharge your business with secure, internal communication.
Townhall
Webinars
Team Collaboration
Learning & Development
Creative Professionals
Get creative with a built in-suite of editing and marketing tools.
eCommerce
Boost sales with interactive video and easy-embedding.
Townhall
Webinars
Team Collaboration
Learning & Development
eLearning & Training
Host and share course materials in a centralized portal.
Sales & Marketing
Attract, engage and convert with interactive tools and analytics.
"Cincopa helped my Enterprise organization collaborate better through video."
Book a Demo
Resources
Resources
Blog
Learn about the latest industry trends, tips & tricks.
Help Centre
Get access to help articles FAQs, and all things Cincopa.
Partners
Check out our valued list of partners.
Product Updates
Stay up-to-date with our latest greatest features.
Ebooks, Guides & More
Customer Stories
Hear how we've helped businesses succeed.
Boost Campaign Performance Through Video
Discover how to boost your next campaign by using video.
Download Now
Pricing
Watch a Demo
Demo
Login
Start Free Trial
Fullscreen mode enhances user immersion during video playback, especially on larger displays or when minimizing distractions is key. With JavaScript's Fullscreen API, developers can provide seamless control over entering and exiting fullscreen mode, detect fullscreen state changes, and apply responsive UI adjustments accordingly. Effective use of this API involves handling browser-specific prefixes, ensuring mobile compatibility, and integrating intuitive controls that prioritize user experience. Fullscreen API Overview The Fullscreen API allows web developers to programmatically control the fullscreen mode of elements, such as video players. The API provides methods to request fullscreen mode, exit fullscreen mode, and check if an element is currently in fullscreen. Key Fullscreen API Methods requestFullscreen() : This method is used to request fullscreen for a specified element, such as the video player. exitFullscreen() : This method exits fullscreen mode. fullscreenElement : This property returns the element that is currently in fullscreen mode, or null if no element is in fullscreen. fullscreenEnabled : This property indicates whether fullscreen mode is available in the current browser or environment. Fullscreen API Browser Compatibility While most modern browsers support the Fullscreen API, there are differences in method names and event handling across browsers. For example, in some browsers, requestFullscreen() may be referred to as webkitRequestFullscreen or mozRequestFullScreen . Therefore, it’s important to handle these browser-specific prefixes. Implementing Fullscreen Mode in a Video Player To implement fullscreen functionality, you'll need to interact with the Fullscreen API through JavaScript. Below is an example of how to create a fullscreen toggle for a video player. Step 1: HTML Setup for Video Player
Your browser does not support the video tag.
Go Fullscreen
Explanation: The
element contains a video source and standard controls. The button, labeled 'Go Fullscreen', will allow users to toggle fullscreen mode. Step 2: JavaScript to Toggle Fullscreen const video = document.getElementById('myVideo'); const fullscreenBtn = document.getElementById('fullscreenBtn'); // Function to request fullscreen function enterFullscreen() { if (video.requestFullscreen) { video.requestFullscreen(); } else if (video.webkitRequestFullscreen) { // Safari video.webkitRequestFullscreen(); } else if (video.mozRequestFullScreen) { // Firefox video.mozRequestFullScreen(); } else if (video.msRequestFullscreen) { // IE/Edge video.msRequestFullscreen(); } } // Function to exit fullscreen function exitFullscreen() { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.webkitExitFullscreen) { // Safari document.webkitExitFullscreen(); } else if (document.mozCancelFullScreen) { // Firefox document.mozCancelFullScreen(); } else if (document.msExitFullscreen) { // IE/Edge document.msExitFullscreen(); } } // Toggle fullscreen on button click fullscreenBtn.addEventListener('click', function() { if (!document.fullscreenElement) { enterFullscreen(); } else { exitFullscreen(); } }); Explanation: enterFullscreen() : Requests fullscreen for the video element, with browser-specific method calls for compatibility. exitFullscreen() : Exits fullscreen using the appropriate browser method. Event Listener : The button listens for clicks to toggle between entering and exiting fullscreen mode. Step 3: Detecting Fullscreen Changes To handle changes in fullscreen state (e.g., when the user presses the Escape key to exit fullscreen), you can listen for fullscreen events. document.addEventListener('fullscreenchange', function() { if (document.fullscreenElement) { console.log('Entered fullscreen'); } else { console.log('Exited fullscreen'); } }); Explanation: fullscreenchange : This event is triggered when the fullscreen state changes. You can use it to log messages or update the UI to indicate whether the player is in fullscreen mode. Advanced Features: Fullscreen API Events and State Management You can further enhance the functionality of your fullscreen feature by listening for additional fullscreen events, such as fullscreenerror, or by tracking the fullscreen state to change UI elements accordingly. document.addEventListener('fullscreenerror', function(e) { console.error('Fullscreen error: ', e); }); // Example: Adding a border around the video when in fullscreen document.addEventListener('fullscreenchange', function() { if (document.fullscreenElement) { video.style.border = '5px solid red'; // Add a border in fullscreen mode } else { video.style.border = ''; // Remove border when exiting fullscreen } }); Explanation: fullscreenerror : This event is fired if an error occurs when attempting to enter or exit fullscreen mode. It’s useful for troubleshooting. Dynamic Styling : Use fullscreen state to adjust the appearance of the player, such as adding or removing borders when entering/exiting fullscreen. Fullscreen Mode Best Practices User Control for Fullscreen Ensure that the user can easily enter and exit full-screen mode by providing clear, accessible controls like a full-screen button. This improves the overall user experience. Handle Browser-Specific Prefixes Since the Fullscreen API is not uniformly implemented across all browsers, ensure that your implementation includes the necessary prefixes (e.g., webkit, moz, ms) to ensure compatibility. Fullscreen on Mobile Devices While full screen is supported on most mobile devices, some may have specific interactions, such as tapping twice to enter full screen or the absence of a button to exit full screen. Ensure your player is mobile-friendly and supports touch events. Use Fullscreen Responsibly Fullscreen mode is often expected to provide an immersive experience, so avoid triggering fullscreen automatically without user input. Let the user decide when to enter full-screen mode.