Reputation: 6030
I'm using Windows 8, Internet Explorer 10, Visual Studio 2013
Here is javascript code :
function simulate(element, eventName)
{
var options = extend(defaultOptions, arguments[2] || {});
var oEvent, eventType = null;
for (var name in eventMatchers)
{
if (eventMatchers[name].test(eventName)) { eventType = name; break; }
}
if (!eventType)
throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
if (true || document.createEvent) // temporary it's always true to check IE
{
oEvent = document.createEvent(eventType);
if (eventType == 'HTMLEvents')
{
oEvent.initEvent(eventName, options.bubbles, options.cancelable);
}
else
{
oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
}
element.dispatchEvent(oEvent);
}
else
{
options.clientX = options.pointerX;
options.clientY = options.pointerY;
var evt = document.createEventObject();
oEvent = extend(evt, options);
element.fireEvent('on' + eventName, oEvent);
}
return element;
}
function extend(destination, source) {
for (var property in source)
destination[property] = source[property];
return destination;
}
var eventMatchers = {
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
}
var defaultOptions = {
pointerX: 0,
pointerY: 0,
button: 0,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
bubbles: true,
cancelable: true
};
My HTML :
<a href="http://google.com" id="rrx" > google </a>
And here is my javascript code that calls simulate :
simulate(document.getElementById('rrx'), "click");
The problem is that I'm not redirected to google web page because IE throws a exception with message that document.createEvent
is not supported.
As far as I know document.createEvent
should be supported with IE9+.
Upvotes: 2
Views: 1574
Reputation: 61666
Add an alert to show document.documentMode
and document.compatMode
, what do you see?
I believe you should have both the correct FEATURE_BROWSER_EMULATION
value in the registry and <!DOCTYPE html>
in the HTML itself, for all modern HTML DOM/JavaScript features to work.
This also applies to the related question of yours.
Upvotes: 2