0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

iframeの値を取得

0
Last updated at Posted at 2026-05-10
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
  });

});

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?