MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See whistlepig.mozilla.org for all notifications.

mozilla
Your Search Results

    navigator.mozApps.getSelf Redirect 1

    « DOM Reference

    Non-standard
    This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

    Summary

    Returns information about the current app, which means an installed app whose domain matches the domain of the calling app. You can use this to determine if an app is installed.

    Note: Multiple apps per origin are not supported. To host several apps from one domain, set up a subdomain for each app. For example: myapp.mydomain.com, otherapp.mydomain.com, and so forth.

    Syntax

    var request = window.navigator.mozApps.getSelf();
    

    Parameters

    None.

    Returns

    getSelf() returns a DOMRequest object. When the success event is fired against the DOMRequest the DOMRequest.result field contains either an App object representing the current app, or a null if getSelf() was called outside of an app (meaning the app is not installed). Before the operation is finished, DOMRequest.result is null.

    If the call is not successful, an error event is fired against the DOMRequest and DOMRequest.error contains a DOMError object, which has information about the error.

    Example

    An example that shows how to use getSelf() with the DOMRequest.onsuccess and DOMRequest.onerror callback properties.

    var request = window.navigator.mozApps.getSelf();
    request.onsuccess = function() {
      if (request.result) {
        // Pull the name of the app out of the App object
        alert("Name of current app: " + request.result.manifest.name);
      } else {
        alert("Called from outside of an app");
      }
    };
    request.onerror = function() {
      // Display error name from the DOMError object
      alert("Error: " + request.error.name);
    };

    If the call is successful an App object is returned in the result property of the returned object. In this example this is request.result. If request.result is null, you know the app is not installed.

    If your app changes its protocol between HTTP and HTTPS, then it is better to use navigator.mozApps.checkInstalled() to check if it is installed.

    Document Tags and Contributors

    Contributors to this page: Sheppy
    Last updated by: Sheppy,