Set window title through payload

Hi,

how to set document.title at runtime through a payload variable?
Is it somehow possible to call the angular function setTitle in an ui_template node?

Thanks,
Manuel

This might help

Thanks for the hint but unfortunately I am not getting it.
So at least this test does not work out:

[
    {
        "id": "a95fc7a5.559d7",
        "type": "ui_template",
        "z": "912f241f.87cae8",
        "group": "4a6429b4.097758",
        "name": "setWindowTitle",
        "order": 0,
        "width": 0,
        "height": 0,
        "format": "<script>\n    (function(scope) {\n      scope.$watch('msg', function(msg) {\n        if (msg) {\n          $window.document.title = msg.payload;\n        }\n      });\n    })(scope);\n</script>",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "templateScope": "global",
        "x": 760,
        "y": 200,
        "wires": [
            [
                "aa7a0149.a3f72"
            ]
        ]
    },
    {
        "id": "196f9a72.f381a6",
        "type": "inject",
        "z": "912f241f.87cae8",
        "name": "",
        "topic": "",
        "payload": "test",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 590,
        "y": 200,
        "wires": [
            [
                "a95fc7a5.559d7"
            ]
        ]
    },
    {
        "id": "aa7a0149.a3f72",
        "type": "debug",
        "z": "912f241f.87cae8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 930,
        "y": 200,
        "wires": []
    },
    {
        "id": "4a6429b4.097758",
        "type": "ui_group",
        "z": "",
        "name": "test",
        "tab": "a15e3d6a.2ebff",
        "order": 2,
        "disp": false,
        "width": "10",
        "collapse": false
    },
    {
        "id": "a15e3d6a.2ebff",
        "type": "ui_tab",
        "z": "",
        "name": "test",
        "icon": "",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Well that's what I would have done probably so if it isn't working, I don't know why I'm afraid.

Put some console.log statements into the ui_template code to make sure you are getting what you expect and when. Also check your browser console to see if there are any errors.

The ui_template can't be targeted to site head but should be widget in the group.
And you don't have $window.document so use window.document instead

1 Like

Thank you hotNipi, that was the trick.

I haven't been able to get this to work. @hotNipi do you have a sample flow I could import and try?

That same flow what was shared by @mj-123 works well if you apply those changes I mentioned.

I'm on the phone currently so no flow sharing for me...

Got it working. Thanks.

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