13

Full screen is working in chrome and other browsers but not working in Safari. Here is my code:

var doc = window.document;
var docEl = document.getElementById("divId");      
//doc.documentElement;

var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;

if(!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement){
  requestFullScreen.call(docEl);
} else { 
  cancelFullScreen.call(doc);
}    
<div id="divId" style="width: 300px;height:60px" > FULL SCREEN </div>
Ivan
  • 34,531
  • 8
  • 55
  • 100
Gaurav
  • 201
  • 1
  • 2
  • 8

2 Answers2

10

It is Element.webkitRequestFullscreen, lower-case s in Fullscreen.
Only Firefox did set their vendor-prefixed version with a camel-cased FullScreen, probably to make everyone's life harder...

var requestFullScreen = docEl.requestFullscreen || docEl.webkitRequestFullscreen || docEl.mozRequestFullScreen ||  docEl.msRequestFullscreen;

As a fiddle since StackSnippets' iframes don't allow fullscreen

Kaiido
  • 123,334
  • 13
  • 219
  • 285
9

The Fullscreen API is not supported in iOS Safari and has partial support in Safari: more on this.

I would recommend to check out Sindre's cross-browser wrapper, screenfull.js around the Fullscreen API, at least check out the source and get what your current project needs.

If you create a web app, that your users will install, here you can find out more about certain meta tags to specify in order to run your web app in full-screen.

user7637745
  • 965
  • 2
  • 14
  • 27
  • 1
    I'm using full screen functionality in angularJS web application. I have tried screenfull.js (https://github.com/sindresorhus/screenfull.js). Same this is working in chrome but not working in safari. – Gaurav Jun 13 '18 at 09:14
  • Do you have any [error messages](https://developer.mozilla.org/en-US/docs/Web/API/Document/onfullscreenerror), when requesting full screen in Safari? – user7637745 Jun 13 '18 at 09:19
  • Yes, In console two error message are: file://platform.twitter.com/widgets.js The requested URL was not found on this server. file://www.google-analytics.com/ga.js The requested URL was not found on this server. – Gaurav Jun 13 '18 at 09:22
  • I have removed these files from code but code is not working in safari. I think, this can be a safari browser configuration issue. – Gaurav Jun 13 '18 at 09:24