As you've learned in the previous recipe, an application can run in full screen or in browser mode. By default, web applications will run on the second one, that is, in the browser mode. Because it's possible to run applications in these two modes, it could be useful to detect which mode is running. Let's explore how to do it.
<head>
section:<script type="text/javascript" charset="utf-8"> var mode = 'browser'; if (navigator.standalone) { mode = "standalone"; } alert("App. running in " + mode + " mode"); </script>
For testing our JavaScript code, we'll add the following onload
attribute to the <body>
tag:
<body onload="init()";>
<body>
and <html>
tags properly. The complete code for this recipe can be found at code/ch03/modes.html
in the code bundle provided on the Packtpub site.The navigator
JavaScript object provided by Safari contains a special property called standalone
. It allows you to detect the running mode of a web application. This recipe uses a simple alert box for displaying this information. However, you can write your own JavaScript function and invoke it when you need to detect this mode. Inside the function, we'll do something more sophisticated than displaying an alert box.
3.133.134.151