Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Window.onbeforeinstallprompt

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

 

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.

The Window.onbeforeinstallprompt property is an event handler for processing a beforeinstallprompt, which is dispatched on mobile when a web manifest exists, but before a user is prompted to save a web site to a home screen.

Syntax

window.addEventListener("beforeinstallprompt", function(event) { ... });
window.onbeforeinstallprompt = function(event) { ...};

Example

The following example uses the beforeinstallprompt function to verify that it is an appropriate time to display an installation prompt to the user. If it is not, the event is redispatched.

var isTooSoon = true;
window.addEventListener("beforeinstallprompt", function(e) { 
  if (isTooSoon) {
    e.preventDefault(); // Prevents prompt display 
    // Prompt later instead: 
    setTimeout(function() { 
      isTooSoon = false; 
      e.prompt(); // Shows prompt 
    }, 10000); 
  } 

  // The event was re-dispatched in response to our request 
  // ... 
});

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 45.0 [1] No support No support No support No support
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support 45.0 [1] No support No support No support No support 45.0 [1]

[1] Behind the flagchrome://flags/#bypass-app-banner-engagement-checks

Specification

This event is not part of a specification.

See Also

ドキュメントのタグと貢献者

 このページの貢献者: jpmedley, teoli
 最終更新者: jpmedley,