简体   繁体   English

将jQuery触发器中的事件参数发送到iframe

[英]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. 我正在触发从父窗口到嵌入式iframe(同一来源)的点击事件,并且我在拾取事件时没有遇到任何问题,但我无法访问自定义参数。 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): 子(名为child_frame的iframe):

$(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. 但是在文档之间,未设置fromParent属性。 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. 从jQuery 1.6开始,您还可以将对象传递给jQuery.Event(),并在新创建的Event对象上设置其属性。

That is, in your case: 也就是说,在你的情况下:

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

Have you already tried it? 你已经试过了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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