0

Despite searching all evening, I still haven't found a solution to this. I have the following layout in the DOM:

<div class="kort_miðja_úti">
  <iframe class="kort_miðja" frameborder="0" width="100%" height="100%" src="...."></iframe>
  <canvas class="kort_canvas"></canvas>
</div>

The canvas is in front, acting as a transparent overlayer on an interactive map from a different site. So when there's a mouse event, it gets it first. It needs to do things on the mouse events, then forward them on to the map so the map can handle them as well. And that's where all the trouble starts.

I first set up a debugging event handler in the canvas which forwardings to the iframe, and add a debugging event handler in the iframe. As expected, the canvas gets its first, and then the iframe. Great.

Now I remove the debugging handler on the iframe, as I want the map to do its own thing. I click, the canvas handler goes off, and then... nothing. No map response. Oh, duh, it's going to the iframe itself, not it's contents. The event should really be going to some deep descendent inside that iframe somewhere, and events don't propagate up the DOM.

Okay, so I try to find which one. I'm going to turn off pointer events for the canvas after it gets an event, call document.elementFromPoint on the screenX and screenY, and then reenable pointer events. And... that gives me just the iframe object, not what's inside. Well, that was no help.

So I try, from the iframe, .contentDocument.elementfromPoint. But that gives me a cross-site scripting error.

And all this may be a moot point because I heard that zooming on phones messes up elementFromPoint.

Well, I'm stumped. Is there no way to do this? How can both I and the map handle the mouse events?

KarenRei
  • 589
  • 6
  • 13
  • On [this question's](https://stackoverflow.com/questions/46841061/intercepting-all-events-handling-then-letting-them-to-object-underneath?noredirect=1#comment80666638_46841061) comments you stated that the iframe were from same domain. Are they or not? The answer will highly depend on this info. And if they're not, do you at least have access to both pages as a developer? – Kaiido Oct 21 '17 at 02:33
  • I did not say that they were from the same domain. They are from different domains. No, I do not have access to both pages. – KarenRei Oct 21 '17 at 13:53
  • Ah I thought it's what you meant by "They do have same origin" Now I see you meant x,y origin... My bad. But then, if you have no control over the iframed document, you are simply out of luck. That is impossible to do. – Kaiido Oct 21 '17 at 14:00
  • Ugh....then my entire project is impossible and all of the work I've done thusfar void because of deficiencies in Javascript. Thanks, Javascript. :Þ – KarenRei Oct 21 '17 at 19:44

0 Answers0