Detect webkit browser in javascript?

Editorial: 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 to determine if a browser is based on a webkit? (Google Chrome, newer Opera, safari);

I tried this:

 var isWebkit = (window.webkitURL != null); if(isWebkit){ alert("i am a webkit based browser!"); } 

Safari doesn't work

+3
javascript jquery browser webkit
Sep 04 '13 at 23:17
source share
5 answers

The main one is the following: w3school JS .

The code:

 <script> txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>"; txt+= "<p>Browser Name: " + navigator.appName + "</p>"; txt+= "<p>Browser Version: " + navigator.appVersion + "</p>"; txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>"; txt+= "<p>Platform: " + navigator.platform + "</p>"; txt+= "<p>User-agent header: " + navigator.userAgent + "</p>"; txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>"; document.getElementById("example").innerHTML=txt; </script> 

But this is not sure about -webkit-.

Here is the fiddle for this, I mean the fiddle for warning -webkit-browser! (Only for Chrome, only for Safari, Opera 15+ is not yet supported!) Jsfiddle.

Here is the jQuery code for this! try the following:

 $(document).ready(function(){ /* Get browser */ $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); /* Detect Chrome */ if($.browser.chrome){ /* Do something for Chrome at this point */ /* Finally, if it is Chrome then jQuery thinks it Safari so we have to tell it isn't */ $.browser.safari = false; } /* Detect Safari */ if($.browser.safari){ /* Do something for Safari */ } }); 

This will display a popup as soon as the windows load!

The best and easiest and most understandable solution would be the following:

 $.browser.chrome = $.browser.webkit && !!window.chrome; $.browser.safari = $.browser.webkit && !window.chrome; if ($.browser.chrome) alert("You are using Chrome!"); if ($.browser.safari) alert("You are using Safari!"); 

These were the basics I found on some sites:

  • w3schools.com
  • /qaru.site / ... (I used this site to search for scripts.
+1
Sep 04 '13 at 23:37
source share

The solution is pretty simple

 if(navigator.userAgent.indexOf('AppleWebKit') != -1){ //this is webkit! } 

AppleWebKit is the name of the webkit rendering engine, so every webkit-based browser should contain this line

MDN page about browser discovery and user agent

but if you need reliable information about the browser engine, you can use this:

 if(typeof window.webkitConvertPointFromNodeToPage === 'function'){ // this is webkit (really it is) } 

Explanation: The userAgent property can be easily faked, so checking for a specific property is much better. But this is not defective, early versions of safari (before 4.0) do not have this property. Chrome supports webkitConvertPointFromNodeToPage from the first version, the opera supports this, as well as its webkit engine

+8
Feb 13 '14 at 14:20
source share

From this post: How to detect Chrome and Safari browser (webkit)

 var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); var isSafari = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor); if (isChrome) alert("You are using Chrome!"); if (isSafari) alert("You are using Safari!"); 

Or a more general webkit:

 var isWebkit = /webkit/.test( navigator.userAgent ); 

You really have to do function detection using something like Modernizr.

+1
Sep 04 '13 at 23:36 on
source share
 alert('webkitRequestAnimationFrame' in window); 

Tested sequentially in Chrome 48 (true), Safari 9.0.2 (true), Opera 35 (true), Firefox 44.0.2 (false)

+1
Mar 04 '16 at 22:30
source share

To find out if it is really webkit:

 isWebkit = /(safari|chrome)/.test(navigator.userAgent.toLowerCase()); 

The word safari can be displayed in both chrome and safari.

0
Jan 17 '15 at 20:19
source share



All Articles