determining why a page is being renderred in compatibility mode?

后端 未结 2 865
旧巷少年郎
旧巷少年郎 2020-12-18 01:55

I have a layout issue which is due to the containing page being rendered in compatibility mode on IE8. Is there a way to detect whats causing IE8 to enter compatibility mod

相关标签:
2条回答
  • 2020-12-18 02:11

    Check if you have any <meta> tags forcing IE into compatibility mode.

    You can force it to render as IE8 (fully CSS 2.1 compliant) if you wish:

    <meta http-equiv="X-UA-Compatible" content="IE=8"/>
    
    0 讨论(0)
  • 2020-12-18 02:25

    Assuming you have a hidden element with the ID compat-warning:

    Javascript w/ jQuery:

    $(function(){
        function showCompatWarning() {
            $('#compat-warning')
                .css('display','block')
                .css('height','auto')
                .show();
        }
        var tridentOffset = navigator.appVersion.indexOf('Trident/');
        if ( tridentOffset === -1 ) return;
        var jscriptVersion = 0;
        /*@cc_on @*/
        /*@if (@_jscript) jscriptVersion = @_jscript_version ; @*/;
        /*@end @*/
        var tridentVersion = parseInt(navigator.appVersion.substr(tridentOffset+8),10);
        var guessIEVersion = tridentVersion + 4;
        if (( document.documentMode && jscriptVersion && jscriptVersion < 10 && jscriptVersion !== document.documentMode ) ||
            ( document.compatMode && document.compatMode === 'BackCompat') ||
            ( document.documentMode && document.documentMode < 10 && document.documentMode != guessIEVersion ))
            showCompatWarning();
    });
    

    Detection and warnings, your first and last lines of defense against compatibility hell.

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