Thursday, March 7, 2013

JavaScript - Detect Quirks Mode state in visitor's browser

Hi, All.

Q: Quirks Mode breaks my front-end. Is it possible to detect Quirks Mode state on visitor? A: Yes, Possible. I will show it off right now.

Now much developers knows about javascript properties, only the discovers or the ones with reach experience.
JavaScripts stores inside it's object, all about page(document).
Document has a lot of interesting information, one of these we will take a look at called "compatMode".
// My Detecting method.
var quirks = false;
(function(){
   if(document.compatMode == 'BackCompat'){
      quirks = true;
   }
}())
Why this way? Only quirks mode making troubles. compatMode will have BackCompat value whenever Quirks Mode is on in browser. This making possible to detect any browser with Quirks Mode and perform your DOM/Data manipulations to satisfy the visitor experience. Have fun. Good Luck!

No comments: