Yizhu's note

  • Home

  • Tags

  • Archives

下載檔案的檔名跨瀏覽器都一樣不亂碼的方法

Posted on 2020-02-04 |

最近專案上有遇到下載檔名時在IE10中文檔名會亂碼的問題,花了一些時間找到解法,把它記錄下來。
這個方法在Chrome, Safari, IE10+, Edge實測都沒問題,理論上IE10之前應該也支援。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* @param {blob} fileFlob - 下載檔案的blob data
* @param {string} fileName - 下載檔案名稱
* @param {string} fileExt - 下檔檔案副檔名
*/
const handleDownloadFile = (fileFlob, fileName, fileExt) => {
if (window.navigator.msSaveOrOpenBlob) {
// IE
window.navigator.msSaveBlob(blob, fileName + '.' + fileExt);
} else {
const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = fileName + '.' + fileExt;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
};

Angular專案支援IE解法

Posted on 2018-08-15 | Edited on 2018-09-28 |

Angular2+的專案預設不支援IE,支援方式如下:

  • 首先去看專案底下的polyfills.ts,將所有和IE有關的polyfills取消註解。

  • 因為需要較高的IE版本才能支援Angular,index.html加入:

    1
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  • 兩個步驟做完就可以解決IE相容性問題了!

表格如何固定表頭擁有捲軸?

Posted on 2018-04-27 | Edited on 2018-09-28 |
  • 原理
  • 先取得thead固定表頭個欄位的寬度,再去調整tbody欄位的寬度。
    Read more »

MQTT如何清除最後遺言?

Posted on 2018-01-10 | Edited on 2018-09-28 |
  • 直接用mqttfx送空的訊息
  • qos = 0
  • retained = true
  • 設定LWT訊息
    Read more »
Yizhu Guo

Yizhu Guo

越努力,越幸運

4 posts
7 tags
GitHub
© 2020 Yizhu Guo
Powered by Hexo v3.7.1
|
Theme – NexT.Mist v6.4.1