1

i am using jquery browser detection function to alert a different value on different browser but seem it is conflict with safari and chrome. they both are alerting same value. this function is working fine in all browser but the problem with safari and chrome only. thanks in advance.

<script type="text/javascript">

$(function (){

    var m= $.browser;


    if(m.webkit) {

        alert('chorme')

        }


    else if(m.safari) {

        alert('safari')

        }

    else {alert('bye bye')}


    })



</script>
2
  • so there is no solution for tat Commented May 18, 2012 at 5:02
  • I feel the urge to quote the docs when they say, "We recommend against using this property; please try to use feature detection instead..." Commented May 18, 2012 at 5:07

2 Answers 2

4

Safari and Chrome use the same rendering engine, Webkit. Look for Safari first, then the other Webkit browsers. There really is no reason to differentiate between the two in a realistic scenario; they will render webpages virtually identically in almost every case.

If you need to separate them, however, try this:

$.browser.safari &= !/chrome/.test(navigator.userAgent.toLowerCase());

if (m.safari) {
    alert('safari')
} else if (m.webkit) {
    alert('chorme')
}
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not on my mac now to test it but it seens fine now.
0

You can try this code:

$.browser 

gives same result for safari and webkit.

Check the doc for $.browser

So you can try here for your solution, but not jquery

2 Comments

how to use this method can please send me some example
@thecodeparadox the thing is that m.webkit will be valid for both chrome and safari so this wouldnt work. Also the navigator properties are not reliable as you can see testing in chrome for example the appCodeName returns Mozilla. All properties can be tested here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.