简体   繁体   中英

browser detection jquery?

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>

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')
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM