Sending event parameters to jQuery trigger in iframe

I fire click events from the parent window into the built-in iframe (of the same origin), and I have no problem picking up the event, but I cannot access the custom parameters. That's what I'm doing...

Parent:

var iframe_doc = window.child_frame.document; var clickEvent = jQuery.Event("click"); clickEvent.fromParent = true; $("p", iframe_doc).trigger(clickEvent); 

Child (iframe named child_frame):

 $(document).click(function(e){ if(typeof e.fromParent === 'undefined' || e.fromParent != true) { // Do something } }); 

When I do something similar in the context of only one page, this is not a problem, and I see this event. But between documents, the fromParent property fromParent not set. Is this what I'm trying to do is even possible?

Thanks!

+4
source share
1 answer

According to the documentation, you can add properties by passing an object to the constructor:

As in jQuery 1.6, you can also pass a jQuery.Event () object and its properties will be set on the newly created Event object.

That is, in your case:

 var clickEvent = jQuery.Event("click", { fromParent: true }); 

Have you tried it yet?

+1
source

Source: https://habr.com/ru/post/1399673/


All Articles