// Function to show the age gate popup
function showAgeGate() {
// Create a div for the popup
const popup = document.createElement('div');
popup.id = 'ageGatePopup';
popup.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
`;
// Create the popup content
popup.innerHTML = `
Are you 18 years or older?
`;
// Add the popup to the page
document.body.appendChild(popup);
// Event listeners for the buttons
document.getElementById('yesButton').addEventListener('click', () => {
// Store a cookie or local storage value to remember the user's choice
localStorage.setItem('ageVerified', 'true');
document.body.removeChild(popup); // Close the popup
});
document.getElementById('noButton').addEventListener('click', () => {
// Redirect to another page or display a message
window.location.href = 'https://www.example.com/age-restricted'; // Example redirect
});
}
// Check if the user has already verified their age
if (localStorage.getItem('ageVerified') !== 'true') {
showAgeGate();
}