I read a book calls ‘Professional Javascript For Web Developers 2nd edition’ and it state that this code can detect browser rendering engine:
<script type="text/javascript">
var client = function(){
var engine = {
ie: 0,
gecko: 0,
webkit: 0,
khtml: 0,
opera: 0,
ver: null
};
return {
engine : engine
};
}();
if(client.engine.ie){
alert("This is internet explorer");
}else if(client.engine.gecko > 1.5){
if(client.engine.ver == "1.8.1"){
alert("This is gecko rendering browser");
}
}else if(client.engine.webkit){
alert("This is web kit");
}else if(client.engine.khtml){
alert("This is khtml");
}else{
alert("none of the above");
}
</script>
but it seems like doesn’t work, so how this code work to detect browser rendering engine?Thanks
If you read the rest of the chapter and download the source
then you can look at client.js:
It still works in IE10 on win7 and Chrome 67 on Win10
It needs a little change to handle IE11 (Trident/) and Edge(Edge/) – see later
It needs a little change to handle IE11 (Trident/) and Edge(Edge/)