@jeffjade
2017-03-28T13:13:15.000000Z
字数 1767
阅读 1439
javascript
function downloadFileForIE (contentOrPath, fileName) {var ifr = document.createElement('iframe')ifr.style.display = 'none'ifr.src = contentOrPathdocument.body.appendChild(ifr)ifr.contentWindow.document.execCommand('SaveAs', false, fileName)document.body.removeChild(ifr)}
ag-test001
@AgilePoint111
downloadFile (filePath, fileName = true) {let aLink = document.createElement('a')aLink.download = fileNameaLink.href = filePathaLink.click()}
<a href="path_to_file" download="proposed_file_name">Download</a>
fileUrl = "download/temlate/?key='advice'";
function downloadFile (downloadUrl, key) {let cForm = document.createElement('form')cForm.setAttribute('target', '')cForm.setAttribute('method', 'get')cForm.setAttribute('style', 'display:none')cForm.setAttribute('action', downloadUrl)let cInput = document.createElement('input')cInput.setAttribute('type', 'hidden')cInput.setAttribute('name', 'key')cInput.setAttribute('value', key)cForm.appendChild(cInput)document.body.appendChild(cForm)cForm.submit()document.body.removeChild(cForm)}
fileUrl = "download/temlate/?fileName='advice.docx&path=adviceFloder'";
function downloadFile (downloadUrl) {let cForm = document.createElement('form')cForm.setAttribute('target', '')cForm.setAttribute('method', 'post')cForm.setAttribute('style', 'display:none')cForm.setAttribute('action', downloadUrl)document.body.appendChild(cForm)cForm.submit()document.body.removeChild(cForm)}
<form method="get" action="file.doc"><button type="submit">Download!</button></form>
$("#fileRequest").click(function() {// // hope the server sets Content-Disposition: attachment!window.location = 'file.doc';});
<button type="submit" onclick="window.open('file.doc')">Download!</button>
