-2

I want to write with javascrip such a condition that if the user enters into my site through google chrome, makes alert or perform any action.. Either if he has entered through mozilla, he could make alert with mozilla or perform any action.

Mehdi Karamosly
  • 5,388
  • 2
  • 32
  • 50

3 Answers3

1
$(document).ready(function(){
navigator.sayswho= (function(){
    var ua= navigator.userAgent, tem, 
    M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
    if(/trident/i.test(M[1])){
        tem=  /\brv[ :]+(\d+)/g.exec(ua) || [];
        return 'IE '+(tem[1] || '');
    }
    if(M[1]=== 'Chrome'){
        tem= ua.match(/\bOPR\/(\d+)/)
        if(tem!= null) return 'Opera '+tem[1];
    }
    M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
    if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);
    alert('youre using: ' + M.join(' '));
    return M.join(' ');
})();

});
JF it
  • 2,403
  • 3
  • 20
  • 30
0

Eh... Despite all the downvotes, I'll give you an answer.

alert (navigator.userAgent)

the navigator.userAgent string will tell you pretty much everything you need to know about what browser someone is using. You can do what you will with that.

durbnpoisn
  • 4,666
  • 2
  • 16
  • 30
0

Try this code:

 if (navigator.userAgent.indexOf('Firefox') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox') + 8)) >= 3.6){//Firefox
     alert("Firefox");
 }
 else if (navigator.userAgent.indexOf('Chrome') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Chrome') + 7).split(' ')[0]) >= 15){//Chrome
     alert("Chrome");
 }
 else if(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Version') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Version') + 8).split(' ')[0]) >= 5){//Safari
     alert("Safari");
 }
 else
 {
     alert(navigator.userAgent);
 }
Vishal Khode
  • 831
  • 2
  • 9
  • 15