印象中IE8是不支持HTML5的,後來零零碎碎看到部分HTML5支持,今天特地歸檔一下,看看IE8到底支持多少HTML5, stackoverflow上有人說,IE8在當年發佈時,Microsoft承諾:With full CSS 2.1, strong HTML 5 support ,參見:http://msdn.microsoft.com/en-us/library/cc288472 。full CSS2.1 沒問題,這個strong HTML5 support 到底在哪裏?爲此特地去Microsoft官方摘錄一下: 跨域
1.網絡離線檢測:window.navigator.onLine 瀏覽器
if(!window.navigator.onLine){ alert('offline'); }
2.本地存儲:window.localStorage 網絡
if( 'localStorage' in window && null != window.localStorage ){ localStorage.setItem('test', 'hello world'); alert(localStorage.getItem('test')); localStorage.removeItem('test'); }
3.Ajax跨域請求 XDomainRequest() ,僅IE8+支持,其餘瀏覽器的XMLHttpRequest對象內置支持跨域請求。 dom
if('XDomainRequest' in window && null != window.XDomainRequest){ // test /* 使用方法同 XMLHttpRequest對象 var rq = new XDomainRequest(); rq.onload = function(){}; rq.open('GET', 'http://www.example.com/'); rq.send(); */ alert('support XDomainRequest'); }4.跨文檔消息傳輸:postMessage()
window.top.postMessage('hello, from cross domain iframe message', 'http://www.example.com');
5.本地JSON對象支持:JSON 兩個方法:JSON.stringify(); JSON.parse(); post
if('JSON' in window && null!=window.JSON){ alert(JSON.parse( JSON.stringify({'hello': 'world'}) )['hello']); }
6.Ajax連接 前進後退支持:window.onhashchange() spa
7.CSS選擇器:document.querySelectorAll(); // 一直覺得不支持! code
果真是很是strong的support啊。 orm