How do I detect type of operating system

#1

I have a permanent android tablet which displays my dashboard, its based on a grid size of 18x12, it works fine however, some times I want to access this dashboard on my iphone 6x12 most of the dashboard looks ok because the android 18 wide grid size is split into sub grids of 6 wide but I have some screens showing video feeds are the full 18 wide by 11 + a singe row of buttons, obviously this does not work well on the iphone and its unusable because I have swipe enabled to move from screen to screen so trying to horizontal scroll is almost impossible.

I know I can use show and hide to get over this like show 18x12 view and hide 6x4 view or visa versa but I would like to try to automate this by detecting if the dashboard is to be or has been opened on the iphone or android tablet.

Some googling, the most popular response to this question on stack overflow seams to be the following code, but were would I put this User Agent code ?

Please advise thanks.

/**
 * Determine the mobile operating system.
 * This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'.
 *
 * @returns {String}
 */
function getMobileOperatingSystem() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;

      // Windows Phone must come first because its UA also contains "Android"
    if (/windows phone/i.test(userAgent)) {
        return "Windows Phone";
    }

    if (/android/i.test(userAgent)) {
        return "Android";
    }

    // iOS detection from: http://stackoverflow.com/a/9039885/177710
    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        return "iOS";
    }

    return "unknown";
}
0 Likes

#2

This code has to run in the client (front-end) browser. So you need to send it to the browser using a Dashboard template node with <script></script> tags.

Of course, you also need to trigger the code which means that you need a way to trigger it when the page first loads.

0 Likes

#3

Thanks for your response, I have been messing with this for a few hours and the following code in a template node prints the platform type to the dashboard as soon as I load my dashboard

like win32 when I log on to the dashboard in windows
iphone for iphone
ipad for ipad
Linux armv7| for android tablet (not sure why it doesn't say android but it doesn't matter)

anyway the bit I am struggling with is how to get the code to send the result as a msg.payload to the output of the template node please help thanks

0 Likes

#4

image

0 Likes

#5

Ok think I have it ...

image

0 Likes

#6

You should only need the script tag part

0 Likes