219
Views
8
Comments
How to detect client browser
Question

Hi All,

Which is the most preferable way to detect client browsers ? I tried GetUserAgent() function and the result returned by the function is "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36". I got the above output for Chrome browser.


Thanks,

Karthik 

mvp_badge
MVP
Rank: #18
Rank: #1315

Hi Karthik!

I have never used the GetUserAgent() function before (because the output is kinda weird to interpret - seems like it shows compatibility rather than current browser), so I would actually suggest using the GetBrowser action from OutsystemsUIWeb. The result is straightforward.

Just got a script from stackoverflow and works for me for React:


// Internet Explorer 6-11
var isIE11 = /*@cc_on!@*/false || !!document.documentMode;

$parameters.IsIE11 = isIE11;

Rank: #572

Hi,


The OutSystemsUI GetBrowser client action works (for Reactive), but with a small adjustment. Input should be ToLower(GetUserAgent()) since this action checks a UserAgent text like
for example "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36" if the word 'chrome' in lowercase is present. I've noted this to OutSystems so hopefully they will fix this.


Regards,

Jordy

Rank: #43

Hi

Please try below code.

----------------------

$(document).ready(function(){


    /* Get browser */

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


    /* Detect Chrome */

    if($.browser.chrome){

        /* Do something for Chrome at this point */

        alert("You are using Chrome!");

        

        /* Finally, if it is Chrome then jQuery thinks it's 

           Safari so we have to tell it isn't */

        $.browser.safari = false;

    }


    /* Detect Safari */

    if($.browser.safari){

        /* Do something for Safari */

        alert("You are using Safari!");

    }


});