0

I am making my application to run only on chrome by using below code,

if($.browser.chrome){
 /* code if it is chrome */
}
else{
   alert("please use google chrome browser");
}

But I am not able to do it with this code. Any help would be very appreciated. Thanks in advance.

Onera
  • 687
  • 3
  • 14
  • 34

2 Answers2

1
if($.browser.webkit)
{

}
else
{
alert("please use google chrome browser");
}
Ameya Deshpande
  • 3,580
  • 4
  • 30
  • 46
1

The answer here JavaScript: How to find out if the user browser is Chrome? is working for me:

function isChrome(){
 var result = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
 return result;
}
           

if( isChrome() ){
 alert("App running...");
}
else{
   alert("please use google chrome browser");
}
Community
  • 1
  • 1
Ala Eddine JEBALI
  • 7,033
  • 6
  • 46
  • 65
  • Why write a function for this? Why not just place `/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)` into the if condition? – NewToJS Jan 25 '17 at 09:26
  • Because you can use the same function `isChrome()` as many time as you need. – Ala Eddine JEBALI Jan 25 '17 at 09:32
  • I am glad it worked. Thanks, @AlaEddineJEBALI. Since I am checking once when starting the application I am going to use in the if only as NewToJS suggested. – Onera Jan 25 '17 at 09:36
  • @Onera well since this is just a copy/paste of this answer http://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome#answer-4565120 I suggest you at least up vote the original answer or leave a comment thanking them as you found it useful. – NewToJS Jan 25 '17 at 09:40
  • 1
    Yes I did, Good thought @NewToJS. appreciate it – Onera Jan 25 '17 at 11:07