# How use window.onload in UI template

**URL:** <https://discourse.nodered.org/t/how-use-window-onload-in-ui-template/74348>\
**Category:** Dashboard\
**Created:** [29 January 2023 10:30 UTC](https://discourse.nodered.org/t/how-use-window-onload-in-ui-template/74348 "2023-01-29T10:30:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![94r4d0x](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/94r4d0x/32/74934_2.png) [@94r4d0x](https://discourse.nodered.org/u/94r4d0x)\
**Post date:** [29 January 2023 10:30 UTC](https://discourse.nodered.org/t/how-use-window-onload-in-ui-template/74348/1 "2023-01-29T10:30:16Z")

</div>

window.onload not work in UI template (header mod or widget)

```auto
<script type="text/javascript">
    window.onload = function() {
      console.log("loaded")
                        };
                    
</script>

```

how use it pls?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [29 January 2023 12:11 UTC](https://discourse.nodered.org/t/how-use-window-onload-in-ui-template/74348/2 "2023-01-29T12:11:51Z")

</div>

I'm fairly sure this came up in another thread recently. I'll give you the same comment. That I believe it is probably due to the fact that the way Dashboard works, the standard ui\_template is executed long after that event has fired.

If you want to use it, you will need to load the script in the HEAD section of the page, not the body. I think ui\_template has a setting for that.

---

<div class="post-metadata">

**Author:** ![94r4d0x](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/94r4d0x/32/74934_2.png) [@94r4d0x](https://discourse.nodered.org/u/94r4d0x)\
**Post date:** [29 January 2023 13:15 UTC](https://discourse.nodered.org/t/how-use-window-onload-in-ui-template/74348/3 "2023-01-29T13:15:23Z")

</div>

> [@94r4d0x](#):
>
> not work in UI template (header mod or widget)

not work in UI template (header mode or widget)  
header mode I meant HEAD section  
I tried what you said, but to no avail, so I decided to put it separately

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 January 2023 16:08 UTC](https://discourse.nodered.org/t/how-use-window-onload-in-ui-template/74348/4 "2023-01-29T16:08:21Z")

</div>

> [@94r4d0x](#):
>
> ` window.onload = function() {`

If you remove the function the message appears.

What are you trying to accomplish ?  
Note that you can capture dashboard load events with the ui-control node.

---

<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:** [28 February 2023 16:08 UTC](https://discourse.nodered.org/t/how-use-window-onload-in-ui-template/74348/5 "2023-02-28T16:08:30Z")

</div>

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