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 linevar 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

varevent = target.ownerDocument.createEvent('MouseEvents'),

to

varevent = document.createEvent("MouseEvents"),

This should create the correct event and fix your

UncaughtTypeError: Cannot read property 'ownerDocument'ofnull

error.

Post a Comment for "Simulate Link Click From Function"