How to use HTML5 in IE 7?

前端 未结 8 1338
长发绾君心
长发绾君心 2021-02-08 11:24

I was wondering whether there is a way to make html5 code visible in Internet Explorer 7 or less.

For example

相关标签:
8条回答
  • 2021-02-08 12:03

    I check whether or not the requesting client supports the application/xhtml+xml mime type (it is part of the accepts header sent the request).

    If it does not, then I send the client a version of the page using div nodes in place of most html5 semantic nodes.

    0 讨论(0)
  • 2021-02-08 12:07

    This (truly) incredible bit of Javascript should fulfill 100% of your HTML5 compatibility needs:

    http://www.modernizr.com/

    0 讨论(0)
  • 2021-02-08 12:15

    IE < 9 doesn't recognize the HTML5 elements and will not generate them. So I use this bit of JS to do the generation:

    var e = ("abbr,article,aside,audio,canvas,datalist,details,
    figure,footer,header,hgroup,mark,menu,meter,nav,output,
    progress,section,time,video,figcaption,summary").split(',');
    
    for (var i = 0; i < e.length; i++){
        document.createElement(e[i]);
    }
    

    I use this conditional comment to check whether I need to run the script

    <!--[if lt IE 9]>
        <script src="js/html5_createElement_for_IE.js"></script>
    <![endif]-->
    

    Of course, you will need to style the tags for IE < 9, but you would need to anyway.

    0 讨论(0)
  • 2021-02-08 12:19

    Start with this: http://html5boilerplate.com/. It should solve most of your problems. It works great.

    0 讨论(0)
  • 2021-02-08 12:20

    IE versions < 9 will not render elements that they don't recognize, so the new HTML5 elements, header, etc are off the list. Other browsers render unrecognized elements, but without styling.

    The way around this is to "show" the new elements to IE by squirting them into the DOM directly using JavaScript. You only have to do this once on each page view.

    The two standard ways to do this are:

    • The Google Shiv: http://code.google.com/p/html5shiv/
    • Modernizr: http://modernizr.com/

    Modernizr also does a whole bunch of other things to do with feature detection.

    0 讨论(0)
  • 2021-02-08 12:21

    Try using chromeframe - http://code.google.com/chrome/chromeframe/

    By itself though you cannot use most of the cool new features of HTML5 with IE7. It just isn't implemented in the browser plain and simple.

    0 讨论(0)
提交回复
热议问题