document.compatModeプロパティ



Document Compatmode Property



document.compatMode used to determine the current rendering browser used. The official explanation: BackCompat: standards-compliant mode off. CSS1Compat: standards-compliant mode is turned on. When document.compatMode equal BackCompat, browser client area width document.body.clientWidth When document.compatMode equal CSS1Compat, the browser client area width is document.documentElement.clientWidth. Browser client area height, the height of the scroll bar, scroll bar Left, Top, and so are the scroll bar above situation. Get an accurate web width and height of the client area, width and height of the scroll bar, scroll bar Left and Top of the code: if (document.compatMode == 'BackCompat') { cWidth = document.body.clientWidth cHeight = document.body.clientHeight sWidth = document.body.scrollWidth sHeight = document.body.scrollHeight sLeft = document.body.scrollLeft sTop = document.body.scrollTop } else { //document.compatMode == 'CSS1Compat' cWidth = document.documentElement.clientWidth cHeight = document.documentElement.clientHeight sWidth = document.documentElement.scrollWidth sHeight = document.documentElement.scrollHeight sLeft = document.documentElement.scrollLeft == 0 ? document.body.scrollLeft : document.documentElement.scrollLeft sTop = document.documentElement.scrollTop == 0 ? document.body.scrollTop : document.documentElement.scrollTop } (The above code is compatible with all popular browsers, including: IE, Firefox, Safari, Opera, Chrome)

複製:https://www.cnblogs.com/vivi1985/archive/2012/04/17/2453768.html