If you have a PWA on your website, this article might be very useful for you. We will learn about how to create a button or trigger button to make it easier to install PWA on devices that use Chromium browsers such as Chrome, Edge, Firefox, but the Safari browser also supports PWA.
By default, PWA will display a notification automatically the first time we access the web. But sometimes notifications donʼt appear after we ignore it. While this button will continue to appear until we install it.
For CSS, you can customize it with your website.
The next step is to save this very simple JavaScript code above the </body> tag on your website.
const _0x5c31 = ['disabled', 'then', 'appinstalled', 'click', 'hidden', 'prompt', 'accepted', 'preventDefault', 'addEventListener', 'userChoice', 'false', 'log', 'true', 'outcome', 'getElementById', 'beforeinstallprompt', 'insBtn', 'deferredPrompt'];
(function (_0x53d54c, _0x4206f6) {
const _0x52cd3c = function (_0x5c3119) {
while (--_0x5c3119) {
_0x53d54c['push'](_0x53d54c['shift']());
}
};
_0x52cd3c(++_0x4206f6);
}(_0x5c31, 0x1d8));
const _0x52cd = function (_0x53d54c, _0x4206f6) {
_0x53d54c = _0x53d54c - 0x0;
let _0x52cd3c = _0x5c31[_0x53d54c];
return _0x52cd3c;
};
const insBtn = document[_0x52cd('0xd')](_0x52cd('0xf'));
let deferredPrompt;
window[_0x52cd('0x8')](_0x52cd('0xe'), _0x465d66 => {
_0x465d66[_0x52cd('0x7')]();
deferredPrompt = _0x465d66;
insBtn[_0x52cd('0x0')] = false;
insBtn[_0x52cd('0x8')](_0x52cd('0x4'), insApp);
});
function insApp() {
deferredPrompt[_0x52cd('0x3')]();
insBtn[_0x52cd('0x1')] = true;
deferredPrompt[_0x52cd('0x6')][_0x52cd('0x9')](_0x3b2e13 => {
if (_0x3b2e13[_0x52cd('0x2')] === _0x52cd('0x5')) {
insBtn[_0x52cd('0x0')] = true;
} else {
}
insBtn[_0x52cd('0x1')] = false;
deferredPrompt = null;
});
}
window[_0x52cd('0x8')](_0x52cd('0xa'), _0x4674d7 => {
console[_0x52cd('0xb')](_0x52cd('0xc'), _0x4674d7);
});
Almost done, and the last is to save the HTML code, save it in the section you want.
<button hidden='' id='insBtn'>Download App</button>
Finally, youʼve made it! If you have any question, please leave a comment.