JavaScript jQuery Basics Working with jQuery Collections Changing Element Properties

Code copied verbatim, but does not work.

I can see that $pdfs.attr('download', true); transfers the attribute of download and sets it to true in the elements of my console but the pdf file does not download. I have checked and double checked the syntax, root properties and everything else I could think of. Using chrome on a Ubuntu OS, could that have something to do with it? code as follows; const $odd = $('a:odd'); // $odd.hide(); const $secureLinks = $('a[href^="https://"]'); // $secureLinks.hide(); const $pdfs = $('a[href$=".pdf"]'); // $pdfs.hide();

// Open link in new tab $secureLinks.attr('target', '_blank'); // Download instead of opening in browser $pdfs.attr('download', true);

Brandyn Lordi
Brandyn Lordi
17,203 Points

Hi matt, Are you using chrome? If so, there is actually a hidden setting that might be the cause of your frustration :)

try this: Chrome settings > Content Settings > PDF documents > enable downloads.

Thank you Brandyn that was spot on my problem. Thank you very much.

2 Answers

Elias Guderian
Elias Guderian
Front End Web Development Techdegree Graduate 14,994 Points

Hallo there, I had the same problem and I changed the setting and it still works so Reinhard Liess you are incorrect. I don't know anything about same-origin links though but I followed the instruction and it worked although it was kinda difficult to find the option. I don't really like googles settings layout.

Reinhard Liess
Reinhard Liess
Full Stack JavaScript Techdegree Student 15,763 Points

Which version of Chrome do you use? According to Can I Use...

Chrome 65 and above only supports same-origin download links.

So that means that this example using a cross-site link won't ever work on Google Chrome (or Mozilla Firefox, for that matter.)