J
jmpinchot
I'm trying to automate Internet Explorer using javascript. I want to
be able to tell IE whether or not to right/alt/ctrl/shift click an
element on the page, so I'm creating an event object by calling
document.createEventObject() and setting the appropriate values on the
event object and then calling element.fireEvent.
The problem is that if I call that method on either an anchor element
or submit input element, either the form is not submitted or IE
doesn't browse to the desired url.
Calling element.click() fixes the problem with allowing the default
action to take place, but doesn't let me control the properties of the
event object.
Is there a way to modify how click() creates the event object, or is
there a way to force the default action for the target element to take
place after calling fireEvent() on it?
Heres the code related to creating and firing the event:
var ieEvent = element.ownerDocument.createEventObject();
ieEvent.detail = 0;
ieEvent.screenX = screenX;
ieEvent.screenY = screenY;
ieEvent.clientX = clientX;
ieEvent.clientY = clientY;
ieEvent.ctrlKey = (clickOptions) ? clickOptions.ctrl : false;
ieEvent.altKey = (clickOptions) ? clickOptions.alt : false;
ieEvent.shiftKey = (clickOptions) ? clickOptions.shift :
false;
ieEvent.metaKey = false;
if (eventType == "mousedown" || eventType == "mouseup") {
ieEvent.button = 1;
} else {
ieEvent.button = 0;
}
ieEvent.relatedTarget = null;
element.fireEvent('on' + eventType, ieEvent);
be able to tell IE whether or not to right/alt/ctrl/shift click an
element on the page, so I'm creating an event object by calling
document.createEventObject() and setting the appropriate values on the
event object and then calling element.fireEvent.
The problem is that if I call that method on either an anchor element
or submit input element, either the form is not submitted or IE
doesn't browse to the desired url.
Calling element.click() fixes the problem with allowing the default
action to take place, but doesn't let me control the properties of the
event object.
Is there a way to modify how click() creates the event object, or is
there a way to force the default action for the target element to take
place after calling fireEvent() on it?
Heres the code related to creating and firing the event:
var ieEvent = element.ownerDocument.createEventObject();
ieEvent.detail = 0;
ieEvent.screenX = screenX;
ieEvent.screenY = screenY;
ieEvent.clientX = clientX;
ieEvent.clientY = clientY;
ieEvent.ctrlKey = (clickOptions) ? clickOptions.ctrl : false;
ieEvent.altKey = (clickOptions) ? clickOptions.alt : false;
ieEvent.shiftKey = (clickOptions) ? clickOptions.shift :
false;
ieEvent.metaKey = false;
if (eventType == "mousedown" || eventType == "mouseup") {
ieEvent.button = 1;
} else {
ieEvent.button = 0;
}
ieEvent.relatedTarget = null;
element.fireEvent('on' + eventType, ieEvent);