javascript - BeforeinstallPromt 事件仍然触发 添加到主屏幕 在 window.location 中设置任何值后提示不起作用
问题描述
在 window.location 中设置任何值后,谷歌的添加到主屏幕功能不起作用。
到目前为止做了什么?
参考:web-fundamentals-app-install-banners
在此实施期间,我正在捕获'beforeInstallPromptEvent'
窗口并在以后需要时使用它。
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;
});
});
上面的代码在正常的旅程中完美运行,但是一旦我在 window.location 中包含一些内容以转到安装在设备中的某个应用程序,它就会停止工作,
当 Truecaller 功能的以下代码与添加到主屏幕一起添加时,它会停止工作:
window.location='xxxxxsdk://some-url/';
我也尝试过使用其他选项重定向到类似location.assign()
但仍然相同的问题的应用程序。
解决方案
嗨)安装应用程序后尝试放置:
window.addEventListener('appinstalled', function() {
// window.location = ...
});
这是文档:https ://developer.mozilla.org/en-US/docs/Web/API/Window/appinstalled_event
推荐阅读
- r - 重复测量的降维:PCA?外交部?(FactoMiner)
- windows-10 - 必须如何设置开发环境来构建 prestashop 主题资产?
- c# - 如何删除 ContextMenu 边框
- c++ - ''的C++多重定义首先定义在这里
- node.js - NodeJs 8 支持哪些版本的 EcmaScript?我可以使用 polyfill 在 Nodejs8 中强制兼容最新的 Ecma 标准吗?
- asp.net - VB。NET 在树视图中添加多个 ChildNode
- ios - 如何在 UITableView (Swift 5) 中隐藏特定单元格的 UIElements?
- python - 对 tf.estimator.Estimator 中的参数感到困惑
- python - 卷积神经网络期望 X 但得到 Y
- sql - TSQL - 计算从昨天到今天的值之间的差异,SELF JOIN 问题