Howto: Dashboard button link to url with no UI template for only the current user on the page

I've seen a form of this question popup here from time to time.
Many of us are not html gods and can't do much in the UI template node. And it does not format to the nice dashboard style without tons of css work.

Yes you can add a link to the dashboard and use the UI node to send people there based on a action. But anyone on that tab will be forwarded too as dashboard is not (mostly) a multi user system.

Then a crazy thought entered my head. The dashboard notification node.
notification
It allows for html and javascript to be in the msg.payload and you can nodesettings

So can it be as simple as formatting a javascript redirect like this:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Redirect url to node-red forum</title> 
</head> 
<body> 
<script> 
    var url= "https://discourse.nodered.org"; 
    window.location = url; 
</script> 
</body> 
</html>

Into a properly formatted payload for the notification node? Will it work?
The answer is YES!!!!!

try out this:

[{"id":"33fb0d2f.a7833a","type":"change","z":"1ca6ee4c.4e6bfa","name":"msg.url = https://google.com","rules":[{"t":"set","p":"url","pt":"msg","to":"https://google.com","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":360,"wires":[["415f23cf.2bd96c"]]},{"id":"deda1028.07bb2","type":"ui_button","z":"1ca6ee4c.4e6bfa","name":"","group":"63d32bef.5e22d4","order":0,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"","x":190,"y":360,"wires":[["33fb0d2f.a7833a"]]},{"id":"9ac06d0e.371","type":"function","z":"1ca6ee4c.4e6bfa","name":"Format Payload for notification node","func":"msg.payload = '<!DOCTYPE html><html><head><title>Redirect url to node-red forum</title></head><body>'+msg.notification_to_user+'<script>var url= \"'+msg.url+'\"; window.location = url; </script></body></html>';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":420,"wires":[["90b001d7.385da"]]},{"id":"415f23cf.2bd96c","type":"change","z":"1ca6ee4c.4e6bfa","name":"notification msg to user = Redirecting","rules":[{"t":"set","p":"notification_to_user","pt":"msg","to":"Redirecting","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":360,"wires":[["9ac06d0e.371"]]},{"id":"90b001d7.385da","type":"ui_toast","z":"1ca6ee4c.4e6bfa","position":"top right","displayTime":"1","highlight":"","sendall":false,"outputs":0,"ok":"OK","cancel":"","raw":true,"topic":"","name":"","x":560,"y":420,"wires":[]},{"id":"63d32bef.5e22d4","type":"ui_group","z":"","name":"button_for_URL","tab":"dfde7706.43a3e","order":1,"disp":false,"width":"6","collapse":false},{"id":"dfde7706.43a3e","type":"ui_tab","z":"","name":"testing_button","icon":"dashboard","disabled":false,"hidden":false}]

You don't have to use a button. Any logic you use that triggers the notification will forward the user.

1 Like

Nice find. Though I might have assumed that including the above in a ui_template node might do the same thing and certainly wouldn't impact the layout in any way.

If you add a ui_template node with just

<script> 
    var url= "https://discourse.nodered.org"; 
    window.location = url; 
</script> 

it will send / forward anyone and anything to https://discourse.nodered.org without pause or logic.
basally any location of the /ui/#!/anything will be forwarded

you never get a chance to interact with the dashboard

also it does not solve the problem of only forwarding the user using that socketid

Ah true, you would need some extra logic. Good points. Very helpful.

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