简体   繁体   中英

Sending event parameters in a jQuery trigger to an iframe

I'm triggering click events from a parent window to an embedded iframe (of the same origin) and am having no trouble picking up the event, but I can't access custom parameters. Here'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 like this within the context of just one page, it's not a problem and I can see the event. But between documents, the fromParent property is not set. Is what I'm trying to do even possible?

Thanks!

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

As of jQuery 1.6, you can also pass an object to jQuery.Event() 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 already tried it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM