# How to get msg when a dashboard is displayed

**URL:** <https://discourse.nodered.org/t/how-to-get-msg-when-a-dashboard-is-displayed/78758>\
**Category:** Dashboard\
**Created:** [28 May 2023 13:53 UTC](https://discourse.nodered.org/t/how-to-get-msg-when-a-dashboard-is-displayed/78758 "2023-05-28T13:53:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marchal-web](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marchal-web/32/66937_2.png) [@Marchal-web](https://discourse.nodered.org/u/Marchal-web)\
**Post date:** [28 May 2023 13:53 UTC](https://discourse.nodered.org/t/how-to-get-msg-when-a-dashboard-is-displayed/78758/1 "2023-05-28T13:53:08Z")

</div>

Hello,  
To get a message when a dashboard/widget is displayed by user, I use a template node with this code:

```auto
<script>
    (function() {
    (function(scope) {
        scope.send({payload: "preload"}); // this gets sent when the view is opened in the browser
    })(scope);
})();
</script>

```

So if I open the dashboard that hold the template, I have at least 3 messages (sometimes 4/5 msg) from the template, most of them have undefine socketid, and some have socketid.

I don't know why this template have this beahvior, is there someone to explain why there's several message coming out the template ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [28 May 2023 14:36 UTC](https://discourse.nodered.org/t/how-to-get-msg-when-a-dashboard-is-displayed/78758/2 "2023-05-28T14:36:07Z")

</div>

You would be best adding an event listener  
This [post](https://discourse.nodered.org/t/how-to-determine-if-a-dashboard-tab-is-active/77284/3) may help

---

<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:** [27 June 2023 14:36 UTC](https://discourse.nodered.org/t/how-to-get-msg-when-a-dashboard-is-displayed/78758/3 "2023-06-27T14:36:28Z")

</div>

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