js - a標簽鏈接地址下載文件


本來是點擊后js加上a標簽的href屬性。但是需要一進入頁面就直接鏈接完整下載地址

<a name="file" download="filename" href="filepath">filename</a>
//filename   ->  a.docx
//filepath   -> /uploadFile/20190802/201908020955486975.docx

**a標簽鏈接的圖片會直接打開,覆蓋頁面,需要加上 target **

<a name="file" download="filename" href="filepath" target="_blank">filename</a>
//filename   ->  a.docx
//filepath   -> /uploadFile/20190802/201908020955486975.docx
<script>
$(document).ready(function () {
        //給file前加上當前主機網址
        $.each($("a[name='file']"), function (k, v) {
            $(v).attr("href", 'http://' + window.location.host + $(v).attr("href"));
        });
    })
</script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM