**how to close node-red browser window by a button in dashboard**

Hi, I show a node-red dashboard working on a thin client from a browser window on a control system.
Stupidly I can not leave node-red window any more, there is no close button. Therfore I want to install a button in my dashboard to close the node-red window. (I don't want to stop node-red only want to close the window).
I tried with an execute node and CTR + F4 but it does not work.
Have you any idea how to solve this?

Thanks for your help in advance

Tim

Do you want to close the browser or just the tab showing the dashboard? If you want to close the browser you could send the browser process a signal to shut down.

I had asked a similar question sometime ago....

Hi Collin,
i only want to close the tab with the node-red dashboard

Regards

Tim

ctrl+w should work..

Thanks for the answer but how can I put that in an exec node? What is the unicode for control+w ?
How to send this from a button in the dash?

Regards Tim

You can not inject key combinations with the exec node, it just doesn't work that way.

The best you may be able to do is insert window.close() into the page via a template node, it will probably need to be set as an on click action for something like a button and there are strict limitations around the page having not backstack history for it to work on most browsers.

See: javascript - How to close current tab in a browser window? - Stack Overflow

1 Like

Try this ui_template. Use at your own risk.

[{"id":"911e3d0e.7d6e9","type":"ui_template","z":"9d1b14cfb6a1526e","group":"325714454937adc5","name":"Close Current Browser Window","order":2,"width":0,"height":0,"format":"<script>\nvar elem = document.documentElement;\n\nthis.scope.action = function closeWindowWithConfirmation() {\nif (confirm(\"Are you sure you want to close the window?\")) {\nwindow.close();\n}\n}\n\ndocument.getElementById(\"close-button\").onclick = closeWindowWithConfirmation;\n\n</script>\n<md-button ng-click=\"send({payload:action()})\">\n    Close Window\n</md-button>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":530,"y":160,"wires":[[]]},{"id":"325714454937adc5","type":"ui_group","name":"DEMO","tab":"fb48ae21810a7ddc","order":2,"disp":false,"width":"25","collapse":false,"className":""},{"id":"fb48ae21810a7ddc","type":"ui_tab","name":"TEST","icon":"dashboard","order":7,"disabled":false,"hidden":false}]

Inspired by this earlier post...

Thank you all for your help!
This works for me.
There is only one restriction. When i open node-red dashboard by a link from another website it works.
Is does not work when i type in the adress in the browser adresslist

flows (8).json (1.5 KB)

image

obviously there are some security related restrictions on closing windows that were not opened by another script. there are worka arounds for it also, but several warning signs around them, so i would not suggest.

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