Question

I intercept all the click events in my iframe with this code:

$(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:

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".

Despite this the e.form is always undefined, where am I wrong?

Was it helpful?

Solution

Seems that you use jQuery, right?

the jQuery event does not have a property from and only normalizes the following event properties:

  • target
  • relatedTarget
  • pageX
  • pageY
  • which
  • metaKey

if you want to pass custom properties with the event you need to trigger your custom event with jQuery itself. http://api.jquery.com/category/events/event-object/ or access the original Event with event.originalEvent

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top