How to click programmatically on “Display images below” in Gmail using jQuery?

*爱你&永不变心* 提交于 2019-12-11 02:05:16

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/4987155/how-to-click-programmatically-on-display-images-below-in-gmail-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!