Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
583 B
2
Indexable
Never
window.addEventListener('message', receiveMessage, false);

        function receiveMessage(event) {
            // Check the content of the message sent and then toggles to show overlay
            if (event.data === 'showShoppingCart') { 
                document.querySelector('#overlay').classList.toggle('active');
            }
        }

//sends message to parent function. Used to show cart
function sendMessageToParent() {
    window.parent.postMessage('showShoppingCart', '*');
}

document.querySelector(".icon").addEventListener("click", sendMessageToParent)
Leave a Comment