Supporting IE8 with HTML5

2019-09-10 12:24发布

问题:

I've noticed that some websites I worked on years ago are now broken in IE8. It took a while to figure out but I see the file — http://html5shim.googlecode.com/svn/trunk/html5.js — that I've always used is now offline.

I don't often build websites these days so I'm a little out of touch. But have devs basically abandoned this browser now? or is there some other alternative file to fix it?

回答1:

If you just want to use HTML5 elements in IE8, for basic styling, you only need this

CSS

article,aside,dialog,figcaption,figure,footer,header,hgroup,
main,nav,section,details,mark,menu,summary { display:block; }

JS (run on load)

(function(d) {
  var e = 'article aside details figcaption figure footer header main mark menu nav section summary'.split(' '),i=e.length;
  while(i--) { d.createElement(e[i]); }
})(document);

Side note:

For IE9 one actually need this (if not use any library, as they normally does this already)

CSS

main { display:block; }