Skip to main content

Using HTML5's FullScreen API

I've been looking into ways in which a web application can be made more user friendly and HTML5 does include some powerful features such as PageVisibility, Navigation Timing, etc,. that can be used to provide good user experience. Today I was looking into FullScreen API that allows you show any of the elements in the DOM in Full-Screen mode. Suppose you have a HTML5 video embedded in a page and would like to play that video in full-screen mode then it is now possible with the FullScreen API. Similarly say if you have an image element, it can also be shown in full screen mode.

To present a element in the full-screen mode you have to call the method requestFullScreen() on that element. I've created a demo that shows a picture and when you click on a button it shows it in the full-screen mode and then changes the picture every three seconds creating a slideshow like experience.

Here's the code:

<!DOCTYPE HTML> <html> <head> <script type="text/javascript"> //list of images for the slideshow var imageList = ["Image3.jpg", "Image4.jpg", "Image5.jpg"]; var count = 0; //invoke this when user wants to see a Full Screen Slideshow function enterFullScreen(){ var elem = document.getElementById("slideshow"); //show full screen elem.webkitRequestFullScreen(); setTimeout(changePicture, 3000); } function changePicture(){ count++; //cycle through the list of images document.getElementById("image1").src = imageList[count % imageList.length]; if (document.webkitIsFullScreen) setTimeout(changePicture, 3000); else //if user exits the full screen mode document.getElementById("image1").src = imageList[0]; } </script> </head> <body> <div id="slideshow"> <img id="image1" src="Image3.jpg"><img> </div> <br> <input type="button" value="Enter full screen mode" onclick=enterFullScreen()> </body> </html>

When you click the button - 'Enter full screen mode' it calls the user defined method - enterFullScreen. In this method a call is made to the method webkitRequestFullScreen on the element that we want to show in full-screen mode. I'm using Google chrome and hence the method requestFullScreen with a prefix 'webkit'. On firefox it would be 'moz'. A slideshow like effect is created by looping through the images in the function changePicture.

To exit from the full-screen mode you can press the 'Esc' key. In the changePicture method I'm checking whether the full-screen mode is still activated by referring to the variable webkitIsFullScreen defined in the document object. It returns true if full-screen mode is activated and false otherwise. 


  1. Hei thanks for the code. I searched many sites, at last I got your web link. check here for future use HTML5 Slider and HTML5 Slideshow

  2. For requesting method in IE, I have used msRequestFullScreen.......But it is not working...What is the solution???

  3. For IE i have used msRequestFullScreen....but it is not working...What is the solution???

  4. FullScreen API is supported in Chrome, Safari and Firefox. Unfortunately it is not supported in IE.


Post a Comment

Popular posts from this blog

A cheat sheet of keyboard shortcuts in ColdFusion Builder

In my last post I have explained about keyboard shortcuts in ColdFusion Builder 2.0. This blog post contains a list of all shortcut keys and I have listed these keyboard shortcuts based on the categories that it falls into. Well, this post was not planned since users can easily get to know the keyboard shortcuts by navigating to the preferences (ColdFusion -> Profiles -> Keys). However, I met Joshua at Scotch on the rocks in Edinburgh and he suggested that it would be nice to have the list of keyboard shortcuts handy. So this post is for those who would like to have the list with them and refer it whenever required.

Keyboard shortcuts for inserting text:

These are the keyboard shortcuts which are used to insert some text into the editor:

CommandKeyboard shortcuts on WindowsKeyboard shortcuts on MacInsert anchor tagCTRL + T, LCMD + T, LInsert bold tagCTRL + T, BCMD + T, BInsert br tagCTRL + T, RCMD + T, RInsert cfabortCTRL + T, ACMD + T, AInsert cfdumpCTRL + T, DCMD + T, DInsert cfs…

De-obfuscating javascript code in Chrome Developer Tools

I had blogged about JavaScript debugging with Chrome Developer Tools some time back, wherein I have explained how these developer tools can help in debugging javascript code. Today Google Chrome 12 was released and my Chrome browser was updated to this version. As with every release, there have been some improvements made on performance, usability etc,. One feature that stood out for me is the ability to De-obfuscate the javascript code.

What is Minification?

Minification is the process of removing unnecessary characters such as white spaces, comments, new lines from the source code. These otherwise would be added to make the code more readable. Minifying the source code helps in reducing the file size and thereby reducing the time taken to download the file. This is the reason why most of the popular javascript libraries such as jQuery are minified. A minified jQuery file is of 31 KB in size where as an uncompressed one is about 229 KB. Unfortunately, debugging minified javascript file…

Custom validation messages for HTML5 Input elements using the constraint validation API

HTML5 has introduced several input types such as EMAIL, URL, RANGE, SEARCH, DATE, TIME, etc,. Most of the modern browsers have implemented them and are ready to be used in a HTML document. Another exciting feature introduced in HTML5 is the form validation. Instead of writing JavaScript to validate users input, browsers can now validate it and show an appropriate message if the validation fails. The validation message is shown in line with the field for which the validation has failed. The default error message is shown when the validation fails. In this post I'll explain how these error messages can be changed.