如何以编程方式点击“在下方显示图片”在Gmail中使用jQuery? [英] How to click programmatically on "Display images below" in Gmail using jQuery?

查看:153
本文介绍了如何以编程方式点击“在下方显示图片”在Gmail中使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个谷歌浏览器扩展程序,为Gmail中使用jQuery的链接显示图像下方添加了一个键盘快捷键。

我试过以下内容来模拟点击失败:

  $(#canvas_frame)。contents()。find(span:contains(显示图片在下面。))鼠标按下()鼠标松开()点击(); 
$(#canvas_frame)。contents()。find(span:contains(Display images below))。click();
$(#canvas_frame)。contents()。find(span:contains(显示图像如下))。mousedown();
$(#canvas_frame)。contents()。find(span:contains(显示图像如下))。
$(#canvas_frame)。contents()。find(span:contains(Display below below))。trigger('click');

有人能指出我的方向吗?


谢谢。

解决方案

  var event = document.createEvent( MouseEvents); 
event.initMouseEvent(click,true,true,window,
0,0,0,0,0,false,false,false,0,null);
$(#canvas_frame span:contains(显示图像如下))[0] .dispatchEvent(event);

注意:不要忘记GMail是多语言的,你可能需要一个更好的方法来选择元素!


I am creating a google chrome extension that adds a keyboard shortcut for the link "Display images below" in Gmail using jQuery.

I have tried the following to simulate the click unsuccessfully:

$("#canvas_frame").contents().find("span:contains(Display images below)").mousedown().mouseup().click();
$("#canvas_frame").contents().find("span:contains(Display images below)").click();
$("#canvas_frame").contents().find("span:contains(Display images below)").mousedown();
$("#canvas_frame").contents().find("span:contains(Display images below)").mouseup();
$("#canvas_frame").contents().find("span:contains(Display images below)").trigger('click');

Could someone point me in the right direction?

Thank you.

解决方案

var event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window,
    0, 0, 0, 0, 0, false, false, false, false, 0, null);
$("#canvas_frame span:contains(Display images below)")[0].dispatchEvent(event);

Note: don't forget that GMail is multilingual, you may need a better method of selecting the element!

这篇关于如何以编程方式点击“在下方显示图片”在Gmail中使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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