How to set target property when simulating mouseclick in javascript?

I want to simulate mouseclick in my javascript code that uses dojo. The action for a real mouseclick will be logged using the dojo file with "ondijitclick".

I know which method / function is being called, and I also have a dijit object to call this method. The method expects a function object as a parameter, so I create a new MouseEvent object. All this works fine, except that I need to set a target value for this event, and I cannot figure out how to do it. This is necessary because the subsequent exception handling accesses the target property, and I cannot avoid it.

So far I have the code:

    dojo.query(".mybutton").forEach(function (node) {
        var target = dojo.query(".myclass").parents("#" + node.id)[0];
        var event = new MouseEvent('click', {
            'view' : window,
            'bubbles': true,
            'cancelable': true
        });
        dijit.byId(node.id)._doEvent(event);
    });

If I add the following line

            'target' : target,

MouseEvent, ( ), target null, ).

- ? , , ?

Edit:

, , , .

, relatedTarget , target null. target null relatedTarget , . .

, . , -. , .

, , target . , genereal, , target.

, , . , , , - .

+4
2

target . , , , javascript . , , , .

, target , . :

dojo.query(".mybutton").forEach(function (node) {
    var target = dojo.query(".myclass").parents("#" + node.id)[0];
    var event = new MouseEvent('click', {
        'view' : window,
        'bubbles': true,
        'cancelable': true
    });
    Object.defineProperty(event, 'target', {value: target, enumerable: true});
    dijit.byId(node.id)._doEvent(event);
});
+7

. . , .

0

All Articles