Iframe click event trong Javascript

Do không thể trực tiếp đọc iframe content(DOM) từ trang mẹ nên phải dựa vào blur event để theo dõi hành động trên iframe.

window.addEventListener('DOMContentLoaded', function () {
    window.focus();

    window.addEventListener('blur', function () {
        setTimeout(function () {
            if (document.activeElement.tagName === 'IFRAME') {
                console.log('clicked');
            }
        });
    });
});

categories