解決跨域下a標籤的download不生效問題

<Button
              onClick={()=> {
                  const oReq = new XMLHttpRequest();
                  oReq.open('GET', '//pricing.daily.alibaba-inc.com/monitor/eventListExcel.json', true);
                  oReq.responseType = 'arraybuffer';
                  oReq.withCredentials = true;
                  oReq.onload = function () {
                    const arrayBuffer = oReq.response; // Note: not oReq.responseText
                    if (arrayBuffer) {
                      const byteArray = new Uint8Array(arrayBuffer);
                      const aLink = document.createElement('a');
                      const blob = new Blob([byteArray], { type: 'application/vnd.ms-excel' });
                      let fileName = '報警通知結果.xls';

                      aLink.download = fileName;
                      aLink.href = URL.createObjectURL(blob);
                      aLink.target = '_blank';
                      aLink.className="J_notOpenInContainer";
                      document.body.appendChild(aLink);
                      aLink.click();
                    }
                  };
                  const form = new FormData();
                  form.append('_scm_token_', window._scm_token_);
                  oReq.send(form);
            
              }}
              params={ this.getQueryData()} >導出</Button>
相關文章
相關標籤/搜索