jquery - How can I force an image link bind by JavaScript to download instead of opening in the same tab? -



jquery - How can I force an image link bind by JavaScript to download instead of opening in the same tab? -

this question has reply here:

how set content-disposition = attachment via javascript? 2 answers

i utilize bind href click event on li element:

$(".attachment_file", "#adlist").each(function() { $(this).click(function() { document.location.href = "upload/attachments/t" + urlparam('recsel') + "/" +$(this).attr("filename"); }); });

the problem when filename image opens image.

how can forcefulness downloading instead of opening it?

i didn't found way alter content-type javascript might impossible (see: how set content-disposition = attachment via javascript?) thing remains changed .htaccess.

i still in javascript changing div within li a anchor jquery replacewith() , add together download , href attribute that, opted much simpler , images opened in new tab:

$(".attachment_file", "#adlist").each(function() { $(this).click(function() { url = "upload/travelrequestattachments/t" + urlparam('recsel') + "/" + $(this).attr("filename"); window.open(url, '_blank'); }); });

javascript jquery javascript-events href

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -