In the client through the JS download file, tried several download methods, IFRAME mode is limited to IE browser, window.open (URL), Location.href=url These two ways in the Chrome browser will also be directly open the file rather than download, Baidu N Long no results, in Google or find the answer, download links here.
Window.downloadfile =function(sURL) {//IOS devices do not support downloading. We have the to inform user on this. if(/(IP)/g.test (navigator.useragent)) {Alert (' Your device does not the support files downloading. Try again in desktop browser. '); return false; } //If in Chrome or safari-download via virtual link click if(Window.downloadFile.isChrome | |Window.downloadFile.isSafari) {//Creating New link node. varlink = document.createelement (' A '); Link.href=sURL; if(Link.download!==undefined) { //Set HTML5 Download attribute. This would prevent file from opening if supported. varFileName = surl.substring (Surl.lastindexof ('/') + 1, surl.length); Link.download=FileName; } //dispatching Click event. if(document.createevent) {varE = document.createevent (' mouseevents '); E.initevent (' Click ',true,true); Link.dispatchevent (e); return true; } } //Force File Download (whether supported by server). if(Surl.indexof ('? ') = = =-1) {sURL+ = '? Download '; } window.open (sURL,' _self '); return true;} Window.downloadFile.isChrome= Navigator.userAgent.toLowerCase (). IndexOf (' Chrome ') >-1; Window.downloadFile.isSafari= Navigator.userAgent.toLowerCase (). IndexOf (' Safari ') >-1;
JS download file to local (multi-browser compatible)