Jump to content
The ibi Community has moved to a new platform: Please Sign In and choose Forgot Password to continue

Is there a piece of code that can identify the browser you a...


Ian Dalton

Recommended Posts

Yes, we do it here. All you need to do it to add the following to Custom Setting in the Admin Console.

# HTTP Header variable capture - Users Browser

HTTP_HEADER_NAME=user-agent

WFS_VAR_NAME=HTTP_user_agent

<call> CopyHTTPHeaderToWFVar (HTTP_HEADER_NAME,WFS_VAR_NAME)

<set> HTTP_user_agent (PASS)

 

Then the variable &HTTP_user_agent will be available at a fex level, which you can analyse / decode

Link to comment
Share on other sites

Waz,

Nice piece of code but I will go further with this trying to answer Ian question

I did a test (-TYPE &HTTP_user_agent) with several browsers and I have the below result for each (browser version in the brackets)

 

FF (81.0.2):

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0

FF (83.0):

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0

IE (11.630.19041.0):

Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

GC (87.0.4280.88):

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) >Chrome/87.0.4280.88 Safari/537.36

Edge (87.0.664.57):

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) >Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.57

 

From the result and your pov, how will you determine the browser used

Something such as this

 

-SET &UsedBrowser = IF &HTTP_user_agent CONTAINS Firefox THEN FireFox

-ELSE IF &HTTP_user_agent CONTAINS Edg THEN Edge

-ELSE IF &HTTP_user_agent CONTAINS Trident THEN IE

-ELSE Chrome;

Link to comment
Share on other sites

Thank you Waz and MartinY. I will give it a go. I did find some javascript which works too

// Opera 8.0+

var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

 

// Firefox 1.0+

var isFirefox = typeof InstallTrigger !== 'undefined';

 

// Safari 3.0+ "[object HTMLElementConstructor]"

var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification));

 

// Internet Explorer 6-11

var isIE = /*@cc_on!@*/false || !!document.documentMode;

 

// Edge 20+

var isEdge = !isIE && !!window.StyleMedia;

 

// Chrome 1 - 79

var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);

 

// Edge (based on chromium) detection

var isEdgeChromium = isChrome && (navigator.userAgent.indexOf("Edg") != -1);

 

// Blink engine detection

var isBlink = (isChrome || isOpera) && !!window.CSS;

 

 

var output = 'Detecting browsers by ducktyping:<hr>';

output += 'isFirefox: ' + isFirefox + '<br>';

output += 'isChrome: ' + isChrome + '<br>';

output += 'isSafari: ' + isSafari + '<br>';

output += 'isOpera: ' + isOpera + '<br>';

output += 'isIE: ' + isIE + '<br>';

output += 'isEdge: ' + isEdge + '<br>';

output += 'isEdgeChromium: ' + isEdgeChromium + '<br>';

output += 'isBlink: ' + isBlink + '<br>';

document.body.innerHTML = output;

Link to comment
Share on other sites

If you were looking to do a browser check for IE for example, here is JavaScript that works in 8206 and 8207 in a Page Designer page:

// Web browser check

 

(function () {

let IE11 = navigator.userAgent.toUpperCase().indexOf("TRIDENT/");

console.log("The IE11 check returns: " + IE11);

let IE11orOlder = navigator.userAgent.toUpperCase().indexOf("MSIE");

console.log("The IE11orOlder check returns: " + IE11orOlder);

 

if (IE11 == -1 && IE11orOlder == -1) {

console.log("You're not using IE 11 or older");

} else {

console.log("You are using IE");

window.addEventListener("iba_pageloaded", function (e){

var page = e.target.ibaObject;

console.log("IE message being added to page title");

page.title("Internet Explorer is not supported for this site, you must use a modern web browser such as Chrome, Edge Chromium, Firefox or Safari.");

});

}

 

})();

 

You would want to stress test this in your environment before deploying since JavaScript can be problematic depending on your code level.

Link to comment
Share on other sites

I always use put a script tag right at the top of the html head element so that it is run right away. If you put it after any other javascript, you have the potential of getting an error in IE if any modern JS is used beforehand, and the browser check might not run.

Using a regular expression makes it really simple:

 

 

 

MDN Web Docs

 

 

 

 

RegExp.prototype.test()

 

The test() method executes a search for a match between a regular expression and a specified string. Returns true or false.

 

 

 

 

 

 

 

 

 

 

<!DOCTYPE html>

<html lang="en-us">

<head>

<meta charset="utf-8" />

<script>

var ua = window.navigator.userAgent.toUpperCase();

var isIE = /MSIE|TRIDENT/.test(ua);

if (isIE) alert("This page not work in Internet Explorer.nnPlease use a more modern browser like:ntGoogle ChromentMicrosoft EdgentMozilla FirefoxntSafari");

</script>

...

</head>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...