Layout engine sniffing by JS question

Does anyone have an idea how to sniff the layout engine by javascript? We know Gecko is for FF and Trident is for IE (windows) and Tasman for IE(Mac), however how can we use js to detect it? It's not a good idea to map the result directly according to the browser and os, but I have no other choice so far.
You mean browser sniffing [:smile:] http://www.google.com/search?q=browser+sniffing&hl=en There's many opinions on this, and equally many different ways to do this,
Thanks. Yes, it's about browser sniffing, however a little complexer. I have got to know how to detect the browser's type and version via javascript, and now I want to obtain the infomation of the browser's layout engine. For example, layout engine for windows IE is Trident while IE for Mac using Tasman. I don't know whether there's a workaround that I can get to know this from any navigator or window object or some other variable, just like what we do by parsing the user-agent variable to get the browser's version infomation.
Detecing the layout engine separate from the browser/os should be quite useful once Maxthon2 fully supports both Trident/Gecko. Not to mention any other browsers that will likely follow suit.
Windows XP with the latest public version of the browser formerly known as MyIE2.
Quote: Original posted bypqee at 2007-02-12 03:06
Detecing the layout engine separate from the browser/os should be quite useful once Maxthon2 fully supports both Trident/Gecko. Not to mention any other browsers that will likely follow suit.
Emm, do you have an idea how to achieve this via JS?
Actually no.  Just pointing out that if someone can figure it out it will help later on.
Windows XP with the latest public version of the browser formerly known as MyIE2.
A simple one:

CODE
if(window.opera) alert('opera');
else if(document.all) alert('IE');
else if(typeof(navigator.product)!="undefined") alert('gecko');
Thanks, but this solution is far not precise enough and it needs further consideration. e.g, layout engine used by Opera should be Presto, IE for windows and Mac use different layout engine, and they are not "IE" exactly.
Naturally that is for a simple illustration. You can test the supported properties in different versions of each rendering engine to get more precise information. I think there are quite plenty such sniffing scripts available in the internet. Or you can go to some more established sites to check out their sniffer scripts. btw I think opera had changed its engine name again in 9.0. It's no longer presto now.
I don't know much about scripting but Google found this that may help:
CODE

// Get Browser engine, to feed correct stylesheet // Gecko Based if (eregi("gecko", $_SERVER['HTTP_USER_AGENT'])) { $engine = "gecko"; } // Opera else if (eregi("opera", $_SERVER['HTTP_USER_AGENT'])) { $engine = "presto"; } // IE & IE Clones else if (eregi("msie", $_SERVER['HTTP_USER_AGENT'])) { $engine = "trident"; } // Other browsers' engines may be related / close to the main ones else if (eregi("Konqueror", $_SERVER['HTTP_USER_AGENT'])) { $engine = "gecko"; } else if (eregi("Safari", $_SERVER['HTTP_USER_AGENT'])) { $engine = "gecko"; } else if (eregi ("avant", $_SERVER['HTTP_USER_AGENT'])) { $engine = "trident"; } // Otherwise, serve the best engine else { $engine = "gecko"; }
Windows XP with the latest public version of the browser formerly known as MyIE2.
I may be dense, but if you know the browser, you know the engine, simple as that. It's not like IE is suddenly goin to run on Presto or Gecko...so depending on which browser is detected, by pure logic you will also know which engine it runs on...they are hardlinked...even if M2 were to run on Gecko, the sniffer would still see that IE DOM isn't there...similarly if you use any of the other browsers, they each are tied to a specific engine, and its the engine which tells you what DOM methods/objects are supported. IE on Windows or IE on Mac is also detectable, so here too you know which engine is under the hood...
If more-or-less correctly identifying between 70-90 % of visitors (dependant on target audience), sure, javascript/DHTML is propably enough. To get to 95-99%, checking HTTP user-agent would help. Ofcourse it's trivial for a browser/user to either disable or change what the DHTML script or user-agent returns to the server. http://www.eit.ihk-edu.dk/instruct/browser...php?e=0,7,22,42 http://gemal.dk/browserspy/ http://sourceforge.net/projects/phpsniff/ OTOH, checking which layout engine a users browsers claims to be using is attacking the problem from the wrong side; instead you should just check whether their browser supports the features you're using on your website, using a combination of DHTML and CSS. http://www.quirksmode.org/css/contents.html http://www.webcredible.co.uk/user-friendly...detection.shtml http://www.westciv.com/style_master/academ...port/index.html However, even if the browser doesn't think it supports CSS , javascript, frames or tables, you should still at least give the user the choice of going to the page meant for modern browsers. Not only meant for security-conscious/paranoid users who have disabled everything, but also for users of certain mobile browsers, various Amiga and Atari browsers, browsers on 8-bit systems such as C64 (Contiki) , Lynx , Dillo
I found that navigator.appName is adequate to identify the browser's type, why so many people use user agent instead? Are there any paticular reason?