1

I have a Chrome extension that dynamically creates links and adds them to a webpage. The links download files. They each have a download attribute to name the files correctly (only works in Chrome, afaik - but it only needs to), as well as href for the url of the file. How can I simulate clicking one of these links?

I don't need to click the version within the document necessarily, just the link object.

Basically, how can I write, in Javascript/JQuery, code to have Chrome download a file named with download at the href location?

The JQuery click() command didn't seem to do anything, though I can't figure out why.

4

2 回答 2

2

我知道这个帖子很旧,但它是搜索的第一个结果,所以对于其他寻求答案的人来说,这里是:

$(css_selector)[0].click();

而你正在这样做 $(function(){ HERE }); 并且在原始页面加载时将一些 js 功能添加到 css_selector,然后您可能想通过设置超时来延迟HERE执行。

于 2016-04-08T13:24:38.343 回答
0

您可以尝试像这样模拟点击

$("your_selector").trigger("click");  

或者像这样

$("your_selector").click();  
于 2013-04-14T20:34:16.830 回答