Create Region
Region Type: Static Content
Static ID: install-app-region
HTML Code:
<div class="install-app-card" id="installAppCard" style="display:none;">
<div class="install-app-icon">
<!--i class="fa-mobile"></i-->
<span aria-hidden="true" class="fa fa-heart fa-anim-flash"></span>
</div>
<div class="install-app-content">
<h3>Install Amader Doctor App</h3>
<p>Get quick access, faster loading, and app-like experience — install it on your device now.</p>
</div>
<button type="button" class="install-app-btn" onclick="installPWA()">
<i class="fa fa-download"></i> Install Now
</button>
<button type="button" class="install-app-close" onclick="dismissInstallCard()">
<i class="fa fa-times"></i>
</button>
</div>
Function and Global Variable Declaration:
===============================
//////////////////////////////////////////////////////
// =========== Install-app-Region ==================//
let deferredPrompt;
window.addEventListener('beforeinstallprompt', function(e) {
e.preventDefault();
deferredPrompt = e;
// যদি ইউজার আগে dismiss না করে থাকে, তাহলে card দেখান
if (!localStorage.getItem('installCardDismissed')) {
var card = document.getElementById('installAppCard');
if (card) {
card.style.display = 'flex';
}
}
});
function installPWA() {
if (!deferredPrompt) return;
deferredPrompt.prompt();
deferredPrompt.userChoice.then(function(choiceResult) {
if (choiceResult.outcome === 'accepted') {
console.log('User installed the app');
}
deferredPrompt = null;
var card = document.getElementById('installAppCard');
if (card) {
card.style.display = 'none';
}
});
}
function dismissInstallCard() {
var card = document.getElementById('installAppCard');
if (card) {
card.style.display = 'none';
}
// ২৪ ঘণ্টার জন্য মনে রাখা, বারবার না দেখানোর জন্য
localStorage.setItem('installCardDismissed', Date.now());
}
// যদি install হয়ে যায়, card হাইড করে দিন
window.addEventListener('appinstalled', function() {
var card = document.getElementById('installAppCard');
if (card) {
card.style.display = 'none';
}
localStorage.setItem('installCardDismissed', Date.now());
});
// পেজ লোড হওয়ার সময় dismiss করা থেকে কতক্ষণ পার হয়েছে চেক করা (২৪ ঘণ্টা পর আবার দেখাবে)
$(document).ready(function() {
var dismissedAt = localStorage.getItem('installCardDismissed');
if (dismissedAt) {
var hoursPassed = (Date.now() - parseInt(dismissedAt)) / (1000 * 60 * 60);
if (hoursPassed < 24) {
localStorage.setItem('installCardDismissed', dismissedAt); // এখনো valid
} else {
localStorage.removeItem('installCardDismissed'); // পুরনো হয়ে গেছে, মুছে দিন
}
}
});
Inline CSS:
=========
/*/////////////////////////////////////////////////////
=========== Install-app-Region ==================*/
.install-app-card {
display: none;
align-items: center;
gap: 18px;
background: linear-gradient(135deg, #0a4a2a 0%, #14805a 100%);
border-radius: 16px;
padding: 20px 24px;
margin-bottom: 24px;
box-shadow: 0 6px 20px rgba(15,143,79,0.25);
position: relative;
}
.install-app-icon {
width: 54px;
height: 54px;
background: rgba(255,255,255,0.18);
backdrop-filter: blur(4px);
border-radius: 14px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.install-app-icon i {
font-size: 24px;
color: #fff;
}
.install-app-content {
flex: 1;
}
.install-app-content h3 {
color: #fff;
font-size: 16px;
font-weight: 700;
margin: 0 0 4px 0;
}
.install-app-content p {
color: rgba(255,255,255,0.85);
font-size: 12.5px;
margin: 0;
line-height: 1.5;
}
.install-app-btn {
background: #fff;
color: #0a4a2a;
border: none;
padding: 11px 22px;
border-radius: 10px;
font-size: 13.5px;
font-weight: 700;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
flex-shrink: 0;
transition: transform 0.2s;
}
.install-app-btn:hover {
transform: translateY(-2px);
}
.install-app-close {
background: transparent;
border: none;
color: rgba(255,255,255,0.7);
font-size: 16px;
cursor: pointer;
padding: 6px;
flex-shrink: 0;
}
.install-app-close:hover {
color: #fff;
}
/* ============ RESPONSIVE ============ */
@media (max-width: 640px) {
.install-app-card {
flex-wrap: wrap;
padding: 16px 18px;
}
.install-app-icon {
width: 42px;
height: 42px;
}
.install-app-icon i {
font-size: 18px;
}
.install-app-content {
flex: 1 1 auto;
min-width: 0;
}
.install-app-content h3 {
font-size: 14px;
}
.install-app-content p {
font-size: 11.5px;
}
.install-app-btn {
width: 100%;
justify-content: center;
order: 3;
margin-top: 10px;
}
.install-app-close {
position: absolute;
top: 10px;
right: 10px;
}
}
