gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:01 25 4
gpt4 key购买 nike

我正在触发从父窗口到嵌入式 iframe(同源)的点击事件,并且在获取事件时没有遇到任何问题,但我无法访问自定义参数。这就是我正在做的...

父级:

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

子(名为 child_frame 的 iframe):

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

当我在一页的上下文中执行类似的操作时,这不是问题,我可以看到事件。但在文档之间,未设置 fromParent 属性。我尝试做的事情是否可行?

最佳答案

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.

也就是说,在你的情况下:

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

你试过了吗?

关于javascript - 将 jQuery 触发器中的事件参数发送到 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9557435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com