Can I use the eventcatcher to catch a click in an IFrame

Hi,
I just tried to use the eventcatcher on an IFrame…and on the surrounding div.
The aim is to trigger an actions simultaneosly on the server an in the wiki.
It works in the div but only outside the IFrame.
Is this possible in theory?

Best wishes Jan

As it stands, no, it’s not possible.

Events like that do not leave the embedded iframe document.

It would be possible using JavaScript to trap events in the iframe and post messages to the outer document -- but that's not trivial and certainly not as friendly as doing it in wikitext.
1 Like

Well technically it is possible…
I implemented it using this trick:

The problem is that the trick works only once. So for me this means closing the tab with the Iframe and reopening the tab to recharge it. It would be nice if the event listener furnished a less bricolage way … because to my mind this can be particularly usefull in combination with IFrames.

1 Like

Honestly, I’m surprised it worked even once.

The days when we could do some pretty clever things with iframes are over – it’s down to security, I’m afraid. Just imagine your bank wrapped in an iframe (styled to ensure you can’t tell just by looking) and allowing all the events to bleed through to the parent (rogue) window.

I did a trial with $eventcatcher and no clicks got through. I’m sticking with my original answer, no, it’s not possible (your SO answer is the same as the solution I provided in the small print).

Good luck with your endeavours though – if you find anything, be sure to let us know.

1 Like

Whereas the first version detects only the first click, this seems to provide a mechanism which continues to detect clicks.
First test positive, I will try to implement it…

1 Like

I think this is a very practical, interesting, discussion. The whole way that iframes have gone is almost a mini-lesson on netology. Somewhat, sometimes, a security too far. I’m sceptical browser makers should arbitrate this kind of thing as they do. It is a bit too much right-on.

Do you have control over the content in the IFrame? If yes you can use post-message. We do something similar with the core plugin library. … But the content has to come from the same origin.

Hi Mario,
yes this is the intention.
Using php to put a file to a place where the wiki can find it and then fetching it with a http-request.

Interesting that if this exists in TW. It would be nice if this mechanism was made usable for other usecases in wikitext!
Jan

1 Like

The problem is, that every usecase needs its own js-code for the specific task it has to fulfil. There is no “once size fits all” …

Your OP says: “Can I use the eventcatcher to catch a click in an IFrame” … There is only 1 sentence what you try to achieve:

The aim is to trigger an actions simultaneosly on the server an in the wiki.

You would need to be more specific about the workflow. eg:

  • action triggered in the wiki
  • action triggered in the iframe
  • action triggered on the server

Not the whole thing. Just enough to make 1 round-trip work. eg: User clicks → IFrame needs to → Server should → IFrame should → User feedback. … or something similar

1 Like

Hi Mario,
I guess a big part of the desired actions me and most of the other users will want to trigger when clicking an IFrame will be importing text or data to the wiki.
If the URL is unknown to the wiki this is not trivial, but possible:

  1. Clicking the IFrame lets the server put a file to a URL known to the wiki. (If this happens several times, this URL will have to change by a pattern to avoid proxies.)
  2. The Wiki catches the click on the frame,
  3. then fetches the text/file by XMLHttpRequest ,
  4. It would be nice to have options to transform this int a tiddler…or do something else with it.

Thus the points 2 to 4 should be configurable in the wiki.