# How to Get Navigator "userAgent" Property

**URL:** <https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409>\
**Category:** Dashboard\
**Created:** [22 September 2021 19:46 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409 "2021-09-22T19:46:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [22 September 2021 19:46 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/1 "2021-09-22T19:46:33Z")

</div>

hello, I would like to get the information contained in the Navigator **userAgent** Property.  
I used the code provided by the [w3schools.com](https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_nav_useragent) website.  
I put this one in a template node. On the screen on the dashboard of my phone for example it gives me the expected result :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/3934532ccb72f32121bf2792045f1bb8921f3eb3.jpeg)

Now, how can I get this response displayed and push it into the msg.payload to be processed in my flow?  
Thanks for help.

(I looked at this [post](https://discourse.nodered.org/t/how-do-i-detect-type-of-operating-system/10093) but I didn't understand how to do it)

```auto
<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the user-agent header sent by the browser to the server.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = "User-agent header sent: " + navigator.userAgent;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [23 September 2021 03:14 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/2 "2021-09-23T03:14:57Z")

</div>

So basically you want to send data from the dashboard to the runtime. The built-in help of the ui\_template node gives us an example how to do it. Basically you will need to use Angular stuff like ng-click and / or the scope object.

Try testing the following code inside an ui template node:

```auto
<script>
var value = navigator.userAgent;
this.scope.action = function() { return value; }
</script>

<md-button ng-click="send({payload:action()})">
    Send the Browser user Agent
</md-button>

```

If you want to send the information without clicking a button is even easier using below code inside the ui template node:

```auto
<script>
    (function(scope){ 
     var nav = navigator.userAgent;
     scope.send({payload:nav});
})(scope);
</script>

```

---

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [23 September 2021 08:17 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/3 "2021-09-23T08:17:31Z")

</div>

Andrei, this is exactly what I'm looking for! 🕶  
To be able to show / Hide some menus depending on whether I'm on a PC or a phone.  
This then allows me to display pages designed for small and large screens.  
Your code works perfectly. It's a pity for me not to know the programming, but with the help of the forum and especially NR I always manage. It's TOP 💥  
Thank you.

From my phone:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/26f55608695050e356a3f00b56c6c5267971ea69.png)

or from my PC:  
 ![Capture d'écran Deepin_zone de sélection _20210923101418](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/affdaaf06cd2f09e4658825be186ab9c0636a144.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 September 2021 08:20 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/4 "2021-09-23T08:20:23Z")

</div>

This is usually done with CSS ...

```css
/* Hide element on Desktop */
@media only screen and (min-width: 981px) {
    .hide-on-desktop {
        display: none !important;
    }
}

/* Hide element on Tablet/Phone */
@media only screen and (max-width: 980px) {
    .hide-on-mobile-tablet {
        display: none !important;
    }
}

```

> **[How To Show / Hide Menu Items On Desktop Or Mobile Devices](https://intercom.help/elegantthemes/en/articles/3109546-how-to-show-hide-menu-items-on-desktop-or-mobile-devices)**
>
> Use different menu items for different device sizes.

---

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [23 September 2021 08:31 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/5 "2021-09-23T08:31:21Z")

</div>

Whohh, Another solution.  
Again I have to try to figure this out, can you just elaborate a little more so I can test this at home?  
How to implement this in a flow, I understood the idea but with the lack of knowledge it's not obvious to make the link with NR.  
This code is put in a template node and therefore in each page to display, right ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 September 2021 08:34 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/6 "2021-09-23T08:34:39Z")

</div>

> [@Jean-Luc](#):
>
> This code is put in a template node and therefore in each page to display, right ?

If you set the UI template to head mode and wrap the CSS in style tags yes...

```html
<style>
/* Hide element on Desktop */
@media only screen and (min-width: 981px) {
    .hide-on-desktop {
        display: none !important;
    }
}

/* Hide element on Tablet/Phone */
@media only screen and (max-width: 980px) {
    .hide-on-mobile-tablet {
        display: none !important;
    }
}
</style>

```

You need to set the CSS selectors (e.g. `hide-on-mobile-tablet`) to target the things you want to show/hide

---

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [23 September 2021 08:40 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/7 "2021-09-23T08:40:34Z")

</div>

Okay, I've got it.  
Can I check a 2nd box for this solution 🤔 😄  
Gentlemen, you are amazing. This forum is a pleasure.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 September 2021 08:43 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/8 "2021-09-23T08:43:24Z")

</div>

Mark the solution you end up using 🙂

Actually, the topic asks how to get agent string so strictly speaking @Andrei answer is the correct solution

---

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [23 September 2021 08:56 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/9 "2021-09-23T08:56:02Z")

</div>

> [@Steve-Mcl](#):
>
> Mark the solution you end up using

🙂 🙂 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 October 2021 08:57 UTC](https://discourse.nodered.org/t/how-to-get-navigator-useragent-property/51409/10 "2021-10-07T08:57:01Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
