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.

2
  • Do you delegate event? How do you bind your event? Commented Apr 14, 2013 at 20:53
  • possible duplicate of Trigger click jquery not working (solution = use the native click method, $('selector')[0].click()) Commented Apr 15, 2013 at 7:11

2 Answers 2

2

I know this thread is old, but it's the first result in search, so for others who seeks answer, here it is:

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

And you're doing it $(function(){ HERE }); and some js functionality is added to css_selector on original page load, then maybe you want to delay HERE execution by setting timeout.

Sign up to request clarification or add additional context in comments.

Comments

0

you can try simulating the click like this

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

or like this

$("your_selector").click();  

1 Comment

Neither of those seem to do anything and I can't figure out why. I checked out the selector and it is identifying the correct element, just no event is firing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.