Writing a web app for Firefox OS

  • Revision slug: Firefox_OS/Writing_a_web_app_for_B2G
  • Revision title: Writing a web app for B2G
  • Revision id: 345651
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Mozilla -> Firefox MarketplaceMoved From Mozilla/Boot_to_Gecko/Writing_a_web_app_for_B2G to Firefox_OS/Writing_a_web_app_for_B2G

Revision Content

B2G 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:

<script>
var manifest_url = "http://my.webapp.com/manifest.json";
</script>

<button onclick="navigator.mozApps.install(manifest_url); return false;">
  Install this awesome app on your homescreen!
</button>

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 B2G browser app and tap the install button.

Revision Source

<p>B2G 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/Apps/Getting_Started">Getting started with making apps</a></li>
  <li><a href="/en-US/docs/Apps/Manifest">App manifest</a></li>
</ul>
<p>Of course, feel free to <a href="/en-US/docs/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/Apps/Apps_JavaScript_API/navigator.mozApps.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>
&lt;script&gt;
var manifest_url = "http://my.webapp.com/manifest.json";
&lt;/script&gt;

&lt;button onclick="navigator.mozApps.install(manifest_url); return false;"&gt;
  Install this awesome app on your homescreen!
&lt;/button&gt;
</pre>
<p>Note: the Install button could also be in an app market, such as the <a href="/en-US/docs/Apps/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 B2G browser app and tap the install button.</p>
Revert to this revision