在Chrome中模拟点击“a”标签 [英] Simulate a click on 'a' tag in Chrome

查看:487
本文介绍了在Chrome中模拟点击“a”标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接('a'标签)。
我试图用javascript点击它。
虽然.click();在FF en IE中表现不错,但在Chrome中失败。
(chrome表示该对象没有click方法)。

触发'onclick'或重定向到'href'不会完成这项工作。



关于如何做到这一点的任何想法?
最好我不会得到一个完整的图书馆。

解决方案

  var event = document.createEvent(MouseEvents); 
event.initMouseEvent(click,true,true,window,
0,0,0,0,
false,false,false,false,
0,空值);
element.dispatchEvent(event);

应该在chrome中工作


I have a link ('a' tag). I'm trying to click it using javascript. While .click(); does well in FF en IE it fails in Chrome. (chrome says the object does not have the click method).

triggering the 'onclick' or redirecting to the 'href' won't do the job.

any ideas on how to do this? Preferably i wouldn't get an entire Library just for this.

解决方案

var event = document.createEvent("MouseEvents");
            event.initMouseEvent("click", true, true, window,
                0, 0, 0, 0, 0,
                false, false, false, false,
                0, null);
            element.dispatchEvent(event);

should work in chrome

这篇关于在Chrome中模拟点击“a”标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆