mozilla

Revision 416669 of Writing a web app for Firefox OS

  • Revision slug: Mozilla/Firefox_OS/Apps/Writing_a_web_app_for_Firefox_OS
  • Revision title: Writing a web app for Firefox OS
  • Revision id: 416669
  • Created:
  • Creator: kohei.yoshino
  • Is current revision? No
  • Comment

Revision Content

Firefox OS apps are just Web apps written with HTML, CSS, and JavaScript. You publish them on the Web like you would publish any other Web site. In order to make the Web site installable as a Web app on the device, you just have to garnish them with a manifest and hook up an install button as explained below.

The following topics are recommended starting points:

Of course, feel free to dive even further into Open Web Apps!

Installing the Web app

With the app and manifest published on the Web, you need to make Gecko aware of it. At install time, Gecko looks up the manifest and adds the necessary entries to the home screen, etc.

To install an app, call the navigator.mozApps.install API. Here's example for an install button that you could embed in your app when you self-host your app:

<button id="install">
  Install this awesome app on your homescreen!
</button>
 
<script>
(function(){
  function install(ev) {
    ev.preventDefault();
    // define the manifest URL
    var manifest_url = "http://my.webapp.com/manifest.webapp";
    // install the app
    var myapp = navigator.mozApps.install(manifest_url);
    myapp.onsuccess = function(data) {
      // App is installed, remove button
      this.parentNode.removeChild(this);
    };
    myapp.onerror = function() {
      // App wasn't installed, info is in
      // installapp.error.name
     };
  };
  // get a reference to the button and call install() on click
  var button = document.getElementById('install');
  button.addEventListener('click', install, false);
})();
</script>

Note: the Install button could also be in an app market, such as the Firefox Marketplace, but it's often very handy to have an "Install as web app" button on the main page of your site.

Now visit your web site in the Firefox OS browser app and tap the install button.

Revision Source

<p>Firefox OS apps are just Web apps written with HTML, CSS, and JavaScript. You publish them on the Web like you would publish any other Web site. In order to make the Web site installable as a Web app on the device, you just have to garnish them with a manifest and hook up an install button as explained below.</p>
<p>The following topics are recommended starting points:</p>
<ul>
  <li><a href="/en-US/docs/Web/Apps/Getting_Started">Getting started with making apps</a></li>
  <li><a href="/en-US/docs/Web/Apps/Manifest">App manifest</a></li>
</ul>
<p>Of course, feel free to <a href="/en-US/docs/Web/Apps">dive even further into Open Web Apps</a>!</p>
<h2 id="Installing_the_Web_app">Installing the Web app</h2>
<p>With the app and manifest published on the Web, you need to make Gecko aware of it. At install time, Gecko looks up the manifest and adds the necessary entries to the home screen, etc.</p>
<p>To install an app, call the <a href="/en-US/docs/Web/API/Apps.install"><code>navigator.mozApps.install</code> API</a>. Here's example for an install button that you could embed in your app when you self-host your app:</p>
<pre class="brush: html">
&lt;button id="install"&gt;
&nbsp; Install this awesome app on your homescreen!
&lt;/button&gt;
&nbsp;
&lt;script&gt;
(function(){
&nbsp; function install(ev) {
&nbsp;&nbsp;&nbsp; ev.preventDefault();
&nbsp;&nbsp;&nbsp; // define the manifest URL
&nbsp;&nbsp;&nbsp; var manifest_url = "http://my.webapp.com/manifest.webapp";
&nbsp;&nbsp;&nbsp; // install the app
&nbsp;&nbsp;&nbsp; var myapp = navigator.mozApps.install(manifest_url);
&nbsp;&nbsp;&nbsp; myapp.onsuccess = function(data) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // App is installed, remove button
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.parentNode.removeChild(this);
&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp; myapp.onerror = function() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // App wasn't installed, info is in
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // installapp.error.name
&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp; };
&nbsp; // get a reference to the button and call install() on click
&nbsp; var button = document.getElementById('install');
&nbsp; button.addEventListener('click', install, false);
})();
&lt;/script&gt;
</pre>
<p>Note: the Install button could also be in an app market, such as the <a href="/en-US/docs/Web/Apps/Publishing/Submitting_an_app">Firefox Marketplace</a>, but it's often very handy to have an "Install as web app" button on the main page of your site.</p>
<p>Now visit your web site in the Firefox OS browser app and tap the install button.</p>
Revert to this revision