title.html
const iframe = document.getElementById('myFrame');
console.log(iframe);
iframe.onload = function () {
console.log('loaded');
const doc =
iframe.contentDocument || iframe.contentWindow.document;
console.log(doc);
console.log(doc.body.innerHTML);
console.log(doc.querySelector('.test'));
};
title.html
$(function () {
const observer = new MutationObserver(() => {
const iframe = document.getElementById('myFrame');
if (!iframe) return;
console.log('iframe found');
observer.disconnect();
iframe.addEventListener('load', function () {
console.log('iframe loaded');
const doc =
iframe.contentDocument ||
iframe.contentWindow.document;
$(doc).on('click', 'a.target', function (e) {
e.preventDefault();
console.log('clicked');
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});