Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger click event on link tag in JS for Android and iPhone

I am developing mobile web application using Sencha Touch (JavaScript & ExtJS). I have a link tag (just <a> tag with href), and I need to trigger click event on it.
I have found that call of myelement.dom.click(); do the job, but it's not working for Android... Is there some kind of universal solution?

UPDATE

I have a container with html code:

<a href="http://google.com" id="link_to_click" target="_blank">CLICK ME</a>

I need to simulate click on this link using only plain JavaScript and ExtJS. The link must be opened in new window/tab.

like image 948
Andrey Rudenko Avatar asked Jan 29 '13 16:01

Andrey Rudenko


1 Answers

Use the HTMLEvents object with document.createEvent() to simulate a click on a link.

var link = document.getElementById( 'link_to_click' ),
    event = document.createEvent( 'HTMLEvents' );

event.initEvent( 'click', true, true );
link.dispatchEvent( event );
like image 171
ThinkingStiff Avatar answered Nov 06 '22 04:11

ThinkingStiff