BeforeInstallPrompt
        
        
          Limited availability
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is not Baseline because it does not work in some of the most widely-used browsers.
非标准: 该特性尚未标准化。我们不建议在生产环境中使用非标准特性,因为它们在浏览器中的支持有限,且可能发生变化或被移除。不过,在没有标准选项的特定情况下,它们可以作为合适的替代方案。
在一个用户被提示”安装“一个网站到移动设备的一个主屏幕之前,BeforeInstallPromptEvent 被 Window.onbeforeinstallprompt 处理程序触发。
该接口继承自Event接口。
构造器
new window.BeforeInstallPromptEvent(name, eventInitOptions)- 
创建一个新的
BeforeInstallPromptEvent. 
属性
继承自父类,Event.
BeforeInstallPromptEvent.platform只读- 
返回一个包含了调度事件的平台(s)的
DOMString数组。这是为希望向用户提供版本选择的 user agent 提供的,例如,“web”或“play”允许用户在 web 版本或 Android 版本之间进行选择。 BeforeInstallPromptEvent.userChoice只读- 
返回一个可以解析为
DOMString的Promise,其值为 'installed' 或 'dismissed',用以判断用户是否选择安装该 PWA。 
方法
BeforeInstallPromptEvent.prompt()- 
立即弹出安装提示。允许开发者按照自己选择的时间弹出安装提示。该方法返回
Promise。 
例子
window.addEventListener("beforeinstallprompt", function(e) {
  // log the platforms provided as options in an install prompt
  console.log(e.platforms); // e.g., ["web", "android", "windows"]
  e.userChoice.then(function(outcome) {
    console.log(outcome); // either "installed", "dismissed", etc.
  }, handleError);
});
  浏览器兼容性
Loading…