在Android和iPhone在JS链接标记触发点击事件 [英] Trigger click event on link tag in JS for Android and iPhone
问题描述
我正在开发使用煎茶触摸(JavaScript的&安培; ExtJS的)移动Web应用程序。我有一个链接标记(只< A>
与标记的href
),我需要触发点击
事件就可以了。
我发现 myelement.dom.click()的该呼叫;
做的工作,但它不工作为Android ...有没有某种通用的解决方案的
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?
更新
我有一个HTML code容器:
I have a container with html code:
<a href="http://google.com" id="link_to_click" target="_blank">CLICK ME</a>
我需要模拟只用普通的这个链接,点击的JavaScript 和 ExtJS的。链接必须在新窗口/标签中打开。
I need to simulate click on this link using only plain JavaScript and ExtJS. The link must be opened in new window/tab.
推荐答案
使用了 HTMLEvents
对象 document.createEvent()
来模拟一个链接的点击。
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 );
这篇关于在Android和iPhone在JS链接标记触发点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!