[英]Custom property event in jQuery
I intercept all the click events in my iframe with this code:我使用以下代码拦截了 iframe 中的所有点击事件:
$(doc.body).on("click", function(e) {
if (e.from === undefined) {
e.preventDefault();
e.stopPropagation();
interceptEvent(e);
}
}
The interceptEvent(e)
sends an XML message (with the path to the original e.target) The message is caught (on another browser) by the function: interceptEvent(e)
发送 XML 消息(带有原始 e.target 的路径)该消息被函数捕获(在另一个浏览器上):
if (document.createEvent) { //Netscape
var evt = document.createEvent("HTMLEvents");
evt.initEvent(value, false, true);
evt.from = 'trigger'; //trigger for recognize a XML programmatically event
return !$('.browser').contents().find(path)[0].dispatchEvent(evt);
}
The objective of this function is to replicate the event.此功能的目的是复制事件。 To avoid loops (interception is active on other browsers too) I add to
dispatchedEvent
a the property "from".为了避免循环(拦截在其他浏览器上也处于活动状态),我向
dispatchedEvent
添加了一个属性“from”。
Despite this the e.form
is always undefined
, where am I wrong?尽管如此,
e.form
总是undefined
,我哪里错了?
Seems that you use jQuery, right?似乎您使用 jQuery,对吗?
the jQuery event does not have a property from and only normalizes the following event properties: jQuery 事件没有来自以下事件属性的属性,仅规范化了以下事件属性:
if you want to pass custom properties with the event you need to trigger your custom event with jQuery itself.如果你想通过事件传递自定义属性,你需要用 jQuery 本身触发你的自定义事件。 http://api.jquery.com/category/events/event-object/ or access the original Event with
event.originalEvent
http://api.jquery.com/category/events/event-object/或使用
event.originalEvent
访问原始事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.