EDITED: I actually used PHP to detect and create a local variable with php tags.
if ( strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'webkit')) {
$is_webkit = "true";
}
How do I detect if the browser is webkit based? (Google Chrome, newer Opera, safari);
I've tried this:
var isWebkit = (window.webkitURL != null);
if(isWebkit){
alert("i am a webkit based browser!");
}
Doesn't work for safari
The solution is pretty simple
if(navigator.userAgent.indexOf('AppleWebKit') != -1){
//this is webkit!
}
AppleWebKit is the name of webkit rendering engine, so every single webkit-based browser must contain this string
MDN page about browser detection & user agent
but if you need trustable information about user's browser engine, you might want to use this:
if(typeof window.webkitConvertPointFromNodeToPage === 'function'){
// this is webkit (really it is)
}
Explanation: userAgent property can be easily spoofed, so checking specific property is a much better way. But it is not defectless, early versions of safari (before 4.0) doesn't have such property. Chrome supports webkitConvertPointFromNodeToPage since first version, opera supports this as well as it's engine transferred to webkit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With