Download file function


Download with a tag. If it is a third-party resource, you need to request it back. Otherwise, it will be opened as a link. Also see if the backend has CORS policy blocking.

//Judge whether it is IE browser or not
   IEVersion() {
      let userAgent =  navigator.userAgent ; // get the useragent string of the browser  
      let isIE =  userAgent.indexOf ("compatible") > -1 &&  userAgent.indexOf ("MSIE") > - 1; // judge if ie < 11 browser  
      let isEdge =  userAgent.indexOf ("edge") > - 1 & &! ISIE; // determine if it is the edge browser of IE  
      let isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
      if(isIE || isEdge || isIE11) {
        return true
      const fileName = ' ITSell.jpeg '// export file name
      //For < a > tags, only Firefox and chrome (kernel) support the download attribute
      //Ie10 above supports blob, but still does not support download
        Const blob = new blob ([content]) // construct a blob object to process data. Content is the BLOB data returned by the request. When the request is made, you should add responsetype ='blob 'to let the server return the blob type
      if ('download' in  document.createElement ('a ') & &! Ieversion()) {// browser supporting a tag Download
        const link =  document.createElement ('a ') // create a tag  =Add attributes to the file name // a tag = 'none'
        link.href =URL.createObjectURL(blob);
        document.body.appendChild(link) () // download
        URL.revokeObjectURL ( link.href )// release URL
        document.body.removeChild (link) // release label
      }Else {// other browsers
        navigator.msSaveBlob(blob, fileName);

Recommended Today

The road of high salary, a more complete summary of MySQL high performance optimization in history

preface MySQL for many linux practitioners, is a very difficult problem, most of the cases are because of the database problems and processing ideas are not clear. Before the optimization of MySQL, we must understand the query process of MySQL. In fact, a lot of query optimization work is to follow some principles so that […]