Run Script onload in a Dashboard Template Node?

2,057 views
Skip to first unread message

haema...@gmail.com

unread,
Mar 24, 2017, 12:22:38 PM3/24/17
to Node-RED
In the Dashboard Template node I want to have it send an output message when someone loads a specific Tab.  The UI Control Node won't work because it doesn't tell you which Tab is activated.

This output message contains information specific to the loaded page that I want downstream nodes to use to do some work.

After searching and trying several things I came up with this code as the HTML part of the template.  It seems reasonable to me but doesn't work.  I'm obviously not understanding something.

       
<img src onerror="myFunction()"> 
<script>
    function myFunction() {
        this.scope.action = function() { return "Im here"; };
    }
</script>

I chained this to a Debug Node.  

I just wanted to see "Im here" show up in the debug window when the page is viewed --> http://<myip>:1880/ui/#/0

I'm not very experienced with this and am hoping there's an easy solution someone can share.

Colin Law

unread,
Mar 24, 2017, 12:36:43 PM3/24/17
to node...@googlegroups.com
This shows you how to send a message to the flow when a browser
view is opened on a template

http://flows.nodered.org/flow/a3485bb4b8065c782e210cced7f21f45

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/6fd462d2-2fe2-4cfc-8571-b6573a3057be%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

haema...@gmail.com

unread,
Mar 24, 2017, 12:49:56 PM3/24/17
to Node-RED
Perfect.  Thank you.  

Guess I didn't search hard enough.

haema...@gmail.com

unread,
Mar 24, 2017, 1:02:34 PM3/24/17
to Node-RED
That can be distilled down to:
 
<script>
(function() {
    (function(scope) {
        scope.send({payload: "preload"}); // this gets sent when the view is opened in the browser
    })(scope);
})();
</script>

Seems to work fine.
Reply all
Reply to author
Forward
0 new messages