Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMikki Pumarejo
Full Stack JavaScript Techdegree Student 8,761 Pointspdf file opens, instead of downloads
I've looked through the answers for similar questions, but those solutions don't seem to work for me. My code seems good. I even double-checked that the download attribute was being attached to the link in DevTools, but every time I click the link, it just opens the pdf file.
Maybe I'm just missing something? I'm not sure. Here's my code, if anyone could let me know if there's something I'm just not getting? Any and all suggestions are greatly appreciated.
const $odd = $('a:odd'); const $secureLinks = $('a[href^="https://"]'); const $pdfs = $('a[href$=".pdf"]');
$secureLinks.attr('target', '_blank').addClass('secure'); $pdfs.attr('download', true).addClass('pdf');
1 Answer
Raynauld Minkema
12,832 PointsI had the same problem. I found this answer
https://teamtreehouse.com/community/jquery-attr-method-for-download-not-working
made it work. Altough it just makes the browser download automaticly. So even without the code, it still downloads. I was not to proud to still see this as a win and pretend I did not notice the coding had nothing to do with it anymore.
At the end of the day, it's more of a browser issue, than a coding issue.