浏览器兼容性(一):IE11问题汇总

开发环境 Angular8.1.0ng-zorro-antd:~8.0.2,前端容器nginx:1.10.1,浏览器 IE11

1、页面打不开

// 问题:
IE11 index.html文件打开后,页面空白
// 解决:
更改tsconfig.json文件:
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    …………
    "target": "es2015",  // 更改为es5
    "lib": [
      "es2018",
      "dom"
    ]
}

2、new Date()转换时间字符串不支持 -,支持 /

// 问题:
IE下new Date("2015-01-05 0:00:00") 会显示NAN
// 解决
用new Date("2015/01/05 0:00:00") 代替

3、不支持EventSource

// 安装
npm install event-source-polyfill 
// 引入eventsource.min.js文件
import 'event-source-polyfill/src/eventsource.min.js'  
// ts
const EventSource = NativeEventSource || EventSourcePolyfill;
this.sse = new EventSource(url); // 连接sse服务器

详见 浏览器兼容性(二):不支持EventSource

4、http缓存问题

// 问题:get请求后续会从浏览器缓存中读取,无法获取最新数据。
// 解决:设置header
const newReq = req.clone({   // 修改前端http拦截器
    setHeaders: {  
        'Cache-Control': 'no-cache',  
        'Pragma': 'no-cache'
     }  
});  
或 add_header Cache-Control no-store;  // 修改nginx配置

详见 浏览器兼容性(三):IE浏览器http请求缓存问题

5、本地下载问题

// 问题: IE11不支持createObjectURL, 谷歌、火狐支持
a['href'] = urlObject.createObjectURL(new Blob([data]);
a['download'] = name;
// 解决: IE11用 msSaveBlob
 window.navigator.msSaveBlob(new Blob([data], name);

详见 浏览器兼容性(四):本地下载

6、svg报错

// 解决:修改polyfills.ts文件
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js';  // Run `npm install --save classlist.js`.

你可能感兴趣的:(前端,兼容性,angular4)