Skip to content Skip to sidebar Skip to footer

Simulate Link Click From Function

I am working on a webpage and I want to simulate a link click. The way i have it setup is a user will click a link from an eblast that we are sending out and when the page loads t

Solution 1:

I use this code to do that

// change to this line
var evt = document.createEvent("MouseEvents");

evt.initMouseEvent('click',true,true,window,0,0,0,0,0,false,false,false,false,0,null);
element.dispatchEvent(evt);

The first line should fix your code.

Then change

var event = target.ownerDocument.createEvent('MouseEvents'),

to

var event = document.createEvent("MouseEvents"),

This should create the correct event and fix your

Uncaught TypeError: Cannot read property 'ownerDocument' of null

error.


Post a Comment for "Simulate Link Click From Function"