Skip to content

script.js #5055

@stfsdr6sgs-eng

Description

@stfsdr6sgs-eng

document.addEventListener('DOMContentLoaded', (event) => {
const modal = document.getElementById('welcomeModal');
const closeButton = document.querySelector('.close-button');
const enterButton = document.getElementById('enterSiteButton');

// Check if the user has visited before using Local Storage
const hasVisited = localStorage.getItem('siteVisited');

if (!hasVisited) {
    // If they haven't visited, show the modal using 'flex' for centering
    modal.style.display = 'flex'; 
}

// Function to close the modal and set the visit flag
function closeModal() {
    modal.style.display = 'none';
    // Set local storage item so the modal doesn't show up again
    localStorage.setItem('siteVisited', 'true');
}

// Event Listeners for closing the modal
closeButton.addEventListener('click', closeModal);
enterButton.addEventListener('click', closeModal);

// Close when the user clicks anywhere outside of the modal content
window.addEventListener('click', (event) => {
    if (event.target === modal) {
        closeModal();
    }
});

// Close modal if the user presses the Escape key
document.addEventListener('keydown', (event) => {
    if (event.key === 'Escape' && modal.style.display === 'flex') {
        closeModal();
    }
});

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions