You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 22, 2024. It is now read-only.
@@ -72,17 +73,21 @@ <h3 id="toc-request">Requesting Full Screen</h3>
72
73
<p>The main JS API’s that you need to care about when building an app or a site that uses full screen API are:</p>
73
74
74
75
<ul>
75
-
<li>[element].requestFullscreen() (currently prefixed for both Blink and Gecko) it will take the element and make it full screen.</li>
76
-
<li>document.cancelFullscreen() (currently prefixed for both Blink and Gecko) it will cancel full screen mode.</li>
77
-
<li>document.fullscreenElement (currently prefixed for both Blink and Gecko) is used to determine if any of the elements are in full screen mode.</li>
76
+
<li><pre>[element].requestFullscreen()</pre> (currently prefixed for both Blink and Gecko) it will take the element and make it full screen.</li>
77
+
<li><pre>document.cancelFullscreen()</pre> (currently prefixed for both Blink and Gecko) it will cancel full screen mode.</li>
78
+
<li><pre>document.fullscreenElement</pre> (currently prefixed for both Blink and Gecko) is used to determine if any of the elements are in full screen mode.</li>
You will notice that in the prefixed versions there is a lot of inconsitency between the casing of the 'S' in screen. This is awkward, but this is the problem with specs that are inflight.
83
+
</blockquote>
84
+
80
85
<p>When your app is full-screen you no longer have the browser chrome available to you. This changes the way that users interact with your experience, they will not have the standard navigation controls such as forwards and backwards, nor will they have their escape hatch refresh button. It is important to cater for this scenario. You can use some CSS selectors to help you change the style and presentation of your site when the browser enters full screen mode.</p>
81
86
82
-
<preclass="prettyprint"><button id=”goFS”>Go full screen<button>
87
+
<preclass="prettyprint"><button id="goFS">Go full screen<button>
83
88
<script>
84
-
var goFS = document.getElementById(“goFS”);
85
-
goFS.addEventListener(“click”, function() {
89
+
var goFS = document.getElementById("goFS");
90
+
goFS.addEventListener("click", function() {
86
91
document.body.requestFullScreen();
87
92
}, false);
88
93
</script></pre>
@@ -93,7 +98,7 @@ <h3 id="toc-request">Requesting Full Screen</h3>
93
98
Damn you vendor prefixes!
94
99
</blockquote>
95
100
96
-
<p> What it currently looks like a lot more complex. Mozilla has created a very useful script that you can use to toggle full screen. As you can see, due to the vendor prefix situation it is rather complex and cumbersome compared to the specified API. Even with a slight smoother option, it is still complex. </p>
101
+
<p> What it currently looks like a lot more complex. <ahref="https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode">Mozilla has created</a> a very useful script that you can use to toggle full screen. As you can see, due to the vendor prefix situation it is rather complex and cumbersome compared to the specified API. Even with a slight smoother option, it is still complex. </p>
@@ -110,7 +115,7 @@ <h3 id="toc-request">Requesting Full Screen</h3>
110
115
}
111
116
}</pre>
112
117
113
-
<p>We web developers hate complexity. A nice high-level abstract API you can use is Sindre Sorhus’ (http://sindresorhus.com/screenfull.js/) “Screenfull.js (https://github.com/sindresorhus/screenfull.js)” module which unifies the two slightly different JS API’s and vendor prefixes into one consistent API.</p>
118
+
<p>We web developers hate complexity. A nice high-level abstract API you can use is <ahref="http://sindresorhus.com/screenfull.js"/>Sindre Sorhus'</a> "<ahref="https://github.com/sindresorhus/screenfull.js">Screenfull.js</a>module which unifies the two slightly different JS API's and vendor prefixes into one consistent API.</p>
114
119
115
120
<h3id="toc-launch">Launching a page Full Screen</h3>
<blockquote>If content is set to yes, the web application runs in full-screen mode; otherwise, it does not. The default behavior is to use Safari to display web content.
128
133
You can determine whether a webpage is displayed in full-screen mode using the window.navigator.standalone read-only Boolean JavaScript property.
<blockquote>You can set up your web app to have an application shortcut icon added to a device's homescreen, and have the app launch in full-screen "app mode" using Chrome for Android’s "Add to homescreen" menu item.</blockquote>
138
143
139
144
<h4>Firefox OS</h4>
140
145
<p>Firefox OS has implemented a installable web app and packaged app model for developers to create apps for the user's phone. This model is a little more complex, but it fits in to a wider strategy of installable apps. The developer has to define a manifest for the app that Firefox OS will parse at install time.</p>
<h3id="toc-dontrely">Don’t rely on navigation controls</h3>
155
160
<p>iOS and Firefox OS don’t every device has a hardware back button, you must ensure that users can navigate to their previous state. There is also no refresh gesture that is directly accessible.</p>
156
161
@@ -184,10 +189,10 @@ <h4>Firefox</h4>
184
189
185
190
<h3id="toc-keepuserin">Keep the user in the full screen experience</h3>
186
191
187
-
<p>The full screen API can be a little finicky sometimes, browsers don’t want to lock users in a full screen page so they will break out of full screen as soon as they possibly can. This means you can’t build a full screen website that spans multiple pages because:</p>
192
+
<p>The full screen API can be a little finicky sometimes, browsers don’t want to lock users in a full screen page so they will break out of full screen as soon as they possibly can. This means you can't build a full screen website that spans multiple pages because:</p>
188
193
189
194
<ul>
190
-
<li>Changing the URL programmatically by using window.location = “http://example.com” breaks out of full screen</li>
195
+
<li>Changing the URL programmatically by using window.location = "http://example.com" breaks out of full screen</li>
191
196
<li>A user clicking on an external link inside your page will exit full screen</li>
192
197
<li>Changing the URL via the navigator.pushState API will also break out of the full screen experience.</li>
193
198
</ul>
@@ -199,12 +204,12 @@ <h3 id="toc-keepuserin">Keep the user in the full screen experience</h3>
199
204
<li>Manage your UI and app state using the # fragment.</li>
200
205
</ol>
201
206
202
-
<p>By using the #syntax to update the url (window.location = “#somestate”), and listening to the window.onhashchange event you can use the browser's own history stack to manage changes in the application state, allow the user to use their hardware back buttons, or offer a simple programmatic back button experience by using the history API - window.history.go(-1)</p>
207
+
<p>By using the #syntax to update the url (window.location = "#somestate"), and listening to the window.onhashchange event you can use the browser's own history stack to manage changes in the application state, allow the user to use their hardware back buttons, or offer a simple programmatic back button experience by using the history API - window.history.go(-1)</p>
203
208
204
209
<h3id="toc-letuserchoose">Let the user choose when to go full screen</h3>
205
210
<p>There is nothing more annoying to the user on the web than doing what they don’t expect. When a user is navigating the your site don’t try and trick them into fullscreen.</p>
206
211
207
-
<p>Don’t intercept the first touch event and issue a requestFullScreen.</p>
212
+
<p>Don't intercept the first touch event and issue a requestFullScreen.</p>
208
213
<ol>
209
214
<li>it is annoying</li>
210
215
<li>Browsers may decided to prompt the user at some point in the future about allowing the app to take up the full screen.</li>
@@ -213,7 +218,7 @@ <h3 id="toc-letuserchoose">Let the user choose when to go full screen</h3>
213
218
<p>If you want to launch apps full screen do think about using the install experiences for each platform.</p>
214
219
215
220
<h3id="toc-nospam">Don't spam the user to install your app to a homescreen</h3>
216
-
<p>If you plan on offering a full screen experience via the installed app mechanisms, then just because you have the ability to detect if a user’s app is not running as an installed app does not mean the user wants to install your app all the time. </p>
221
+
<p>If you plan on offering a full screen experience via the installed app mechanisms, then just because you have the ability to detect if a user's app is not running as an installed app does not mean the user wants to install your app all the time. </p>
217
222
218
223
<h3id="toc-documentfullscreen">Making the document full screen</h3>
219
224
<p>It is natural to think that you take the body element full screen, but if you are on a WebKit or Blink based rendering engine you will see it has an odd effect of shrinking the body width to the smallest possible size that will contain all the content (Mozilla Gecko is fine). This, more than likely is not what you want.</p>
@@ -223,34 +228,34 @@ <h3 id="toc-documentfullscreen">Making the document full screen</h3>
223
228
<h3id="toc-videofullscreen">Making a video element full screen</h3>
224
229
<p>To make a video element fullscreen it is exactly the same as making any other element full screen. You call the `requestFullScreen` method on the video element.</p>
var videoElement = document.getElementById(“videoElement”);
233
+
var goFS = document.getElementById("goFS");
234
+
goFS.addEventListener("click", function() {
235
+
var videoElement = document.getElementById("videoElement");
231
236
videoElement.requestFullScreen();
232
237
}, false);
233
238
</script></pre>
234
239
235
240
<p>If your <video> element does not have the controls attribute defined, there will be no way for the user to control the video once they are full screen. The recommended way to do this is to have a basic container that wraps the video and the controls that you want the user to see.</p>
236
241
237
-
<preclass="prettyprint"><div id=”container”>
242
+
<preclass="prettyprint"><div id="container">
238
243
<video><video>
239
244
<div>
240
245
<button>Play<button>
241
246
<button>Stop<button>
242
-
<button id=”goFS”>Go full screen<button>
247
+
<button id="goFS">Go full screen<button>
243
248
<div>
244
249
<div>
245
250
<script>
246
-
var goFS = document.getElementById(“goFS”);
247
-
goFS.addEventListener(“click”, function() {
248
-
var container = document.getElementById(“container”);
251
+
var goFS = document.getElementById("goFS");
252
+
goFS.addEventListener("click", function() {
253
+
var container = document.getElementById("container");
249
254
container.requestFullScreen();
250
255
}, false);
251
256
<script></pre>
252
257
253
-
<p>This actually gives you a lot more flexibility because you can combine the container object with the CSS pseudo selector (for example to hide the “goFS” button.)</p>
258
+
<p>This actually gives you a lot more flexibility because you can combine the container object with the CSS pseudo selector (for example to hide the "goFS" button.)</p>
254
259
255
260
<preclass="prettyprint"><style>
256
261
#goFS::full-screen #goFS {
@@ -265,9 +270,8 @@ <h3 id="toc-videofullscreen">Making a video element full screen</h3>
265
270
<style></pre>
266
271
267
272
<h2id="conslusions">Conclusions</h2>
268
-
<p>Whilst we don’t have a full standardised and implemented API, using some of the guidance presented in this article you can easily build experiences that take advantage of the users entire screen irrespective of the client.</p>
273
+
<p>Whilst we don't have a full standardised and implemented API, using some of the guidance presented in this article you can easily build experiences that take advantage of the users entire screen irrespective of the client.</p>
269
274
270
275
<p>If you know of any good patterns for full-screen, leave a comment and we can let the world know. If you know of anti-patterns in full-screen let us know so we can update the article to save the frustrations of millions of users on the web. </p>
0 commit comments