In JavaScript can I make a “click” event fire programmatically for a file input element?

前端 未结 28 1339
囚心锁ツ
囚心锁ツ 2020-11-21 06:29

I\'d like to make a click event fire on an tag programmatically.

Just calling click() doesn\'t seem to do anything or at lea

28条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 06:59

    Hey this solution works. for download we should be using MSBLOB

    $scope.getSingleInvoicePDF = function(invoiceNumberEntity) {
       var fileName = invoiceNumberEntity + ".pdf";
       var pdfDownload = document.createElement("a");
       document.body.appendChild(pdfDownload);
    
       AngularWebService.getFileWithSuffix("ezbillpdfget",invoiceNumberEntity,"pdf" ).then(function(returnedJSON) {
           var fileBlob = new Blob([returnedJSON.data], {type: 'application/pdf'});
           if (navigator.appVersion.toString().indexOf('.NET') > 0) { // for IE browser
               window.navigator.msSaveBlob(fileBlob, fileName);
           } else { // for other browsers
               var fileURL = window.URL.createObjectURL(fileBlob);
               pdfDownload.href = fileURL;
               pdfDownload.download = fileName;
               pdfDownload.click();      
           }
       });
    };
    

    For AngularJS or even for normal javascript.

提交回复
热议问题