ie兼容问题

ie 兼容性问题

  1. eval(将字符串转换为代码执行)的使用
  2. 不支持自定义事件 CustomEvent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 封装一个CustomEvent
(function(){
if(typeof window.CustomEvent ==== 'undefined'){
function (event, params){
params = params || {
bubbles:false,
cancelable:false,
detail:undefined
};
var evt = document.createEvent('Events');
var bubbles = true;
for(var name in params){
name === 'bubbles' ? (bubbles = !!params[name]) : (evt[name] = params[name]);
};
evt.initEvent(event, bubbles, true);
return evt;
};
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
}
})()
// 另一种写法
if(!window.CustomEvent){
widow.CustomEvent = function(type, config){
config = config || { bubbles:false,cancelable:false,detail:undefined};
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(type, config,bubbles, config.cancelable, config.detail);
return evt;
}
window.CustomEvent.prototype = window.Event.prototype;
}
  1. localstorage 同一域名多个 tab 页内容不能够同步更新
    • 解决:在 localStorage 取值之前,添加或是设置某一个条目的值