简体   繁体   English

BeforeinstallPromt 事件仍然触发 添加到主屏幕 在 window.location 中设置任何值后提示不起作用

[英]BeforeinstallPromt event fired still Add to home screen Prompt not working after setting any value in window.location

Add to Home Screen feature of google is not working after setting any value in window.location.在 window.location 中设置任何值后,谷歌的添加到主屏幕功能不起作用。

What has been done so far?到目前为止做了什么?

Refer: web-fundamentals-app-install-banners参考:web-fundamentals-app-install-banners

During this implementation I am capturing the 'beforeInstallPromptEvent' of window and using it later whenever required.在此实施期间,我正在捕获 window 的'beforeInstallPromptEvent' ,并在以后需要时使用它。

PFB the Code Snippet for the same: PFB 相同的代码片段:

window.addEventListener('beforeinstallprompt', (e) => {
  deferredPrompt = e;
  // Update UI notify the user they can add to home screen
  showInstallPromotion();
});


btnAdd.addEventListener('click', (e) => {
  // hide our user interface that shows our A2HS button
  btnAdd.style.display = 'none';
  // Show the prompt
  deferredPrompt.prompt();
  // Wait for the user to respond to the prompt
  deferredPrompt.userChoice
    .then((choiceResult) => {
      if (choiceResult.outcome === 'accepted') {
        console.log('User accepted the A2HS prompt');
      } else {
        console.log('User dismissed the A2HS prompt');
      }
      deferredPrompt = null;
    });
});

This above code works perfectly in normal journey but it stopworking as soon as I include something in window.location to go to some app which in install in the device,上面的代码在正常的旅程中完美运行,但是一旦我在 window.location 到 go 包含一些安装在设备中的应用程序,它就会停止工作,

When the below code for Truecaller functionality is added in tandem with Add to Home Screen, it stops working:当 Truecaller 功能的以下代码与添加到主屏幕一起添加时,它会停止工作:

window.location='xxxxxsdk://some-url/';

I have also tried with other options to redirect to app like location.assign() but still same issue.我还尝试使用其他选项重定向到诸如location.assign()之类的应用程序,但仍然是同样的问题。

Hi) try to put it after the app is installed:嗨)安装应用程序后尝试放置:

window.addEventListener('appinstalled', function() {
  // window.location = ...
});

Here is the doc: https://developer.mozilla.org/en-US/docs/Web/API/Window/appinstalled_event这是文档: https://developer.mozilla.org/en-US/docs/Web/API/Window/appinstalled_event

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM