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?

More than 3 years have passed since last update.

iframeで子フレームのイベントを親フレームで拾う

Last updated at Posted at 2020-11-16

モーダル系のチャットサービスでの行動を計測するためにイベントを取得しようと思ったら、チャット枠がiframeで作られていた。

分かりやすい記事にまとめられていたため解決!

感謝です。

・・・と思ったら、ローカルでテストすると何故か動かない。。

かなり悩んでしまったが、ローカル環境(file://)ではファイルが違うと別オリジンになるとやらで、フレーム外から直接フレーム内へアクセスすることができないよう。。

本番で動けばよいので、ローカルでの検証をしないことに。

ふう、できた、と思ったら、やはり動かない。。

というよりも、そもそもiframeの読み込み元が別ドメインなので、その場合はほぼ無理ということを知る。。

理由は、ブラウザ側のセキュリティのよう。

豊富としては、このように子フレーム側で「window.parent.postMessage("value","target");」というのを送って、親フレームで受け取るという方法になるみたい。

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?