4

I'm trying to make an extension that lets you click on an iframe in order to remove it (the iframe element) from the page.

I can detect the click only from inside the iframe, but removing the element I have to do from the parent document. This is difficult if the iframe doesn't have the same origin. I can send a message from the iframe content script to the parent content script, but how can the parent find the correct element? As far as I can tell I only have a frameId.

dskloet
  • 91
  • 7
  • See [Detect mousemove when over an iframe?](http://stackoverflow.com/a/15318321) - and replace `mousemove` with `click`. – wOxxOm Jul 31 '16 at 16:26
  • That only works "if the cross-domain policy is satisfied" but I don't think I have control over that. – dskloet Jul 31 '16 at 16:44
  • Does [this](http://stackoverflow.com/a/30359348/3563439) resolve your problem? – masa Jul 31 '16 at 16:54
  • https://gist.github.com/jaydson/1780598 - this seems to be working without the need to modify names of iframes or CSP. – wOxxOm Jul 31 '16 at 16:57
  • I'll have to try but they both look useful. Thanks! – dskloet Jul 31 '16 at 17:34
  • In the end I ended up cheating. I cover all iframes with other divs and I listen for clicks on those divs. Won't work for all use cases but it seems to work for mine. – dskloet Jul 31 '16 at 18:56
  • Found some relevant discussion / code here: https://stackoverflow.com/a/8699879/682317 – Motin Nov 02 '18 at 16:44

0 Answers0