window.open下載文件


function openwin(url) {
    var a = document.createElement("a");
    a.setAttribute("href", url);
    a.setAttribute("target", "_blank");
    a.setAttribute("id", "camnpr");
    document.body.appendChild(a);
    a.click();
}

 通過js的ajax請求驗證一個資源文件地址是否存在,存在打開連接,不存在提示!

<script src="../js/jquery-1.12.4.min.js" type="text/javascript"></script>
function svnOpen(address) {
    var response = $.ajax({
        url: address,
        type: 'HEAD',
        async: false
    }).status;

    if (response=="404") {
        alert("文件不存在!"); 
    } else {
        openwin(address);
    }
}
function openwin(url) {
    var a = document.createElement("a");
    a.setAttribute("href", url);
    a.setAttribute("target", "_blank");
    a.setAttribute("id", "camnpr");
    document.body.appendChild(a);
    a.click();
}

 

 

const a = document.createElement("a");
                document.body.appendChild(a);
                a.style = "display: none";
                a.href = canvas.toDataURL();
                a.download = name;
                a.click();
                document.body.removeChild(a);


免責聲明!

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



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