Skip to content

Commit

Permalink
Update custom-code.md
Browse files Browse the repository at this point in the history
  • Loading branch information
josephrocca authored Apr 9, 2023
1 parent c90d46d commit c8d63f1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/custom-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ oc.thread.on("MessageAdded", async function() {

### "<function> is not defined" in click/event handlers
The following code won't work:
```
```js
function hello() {
console.log("hi");
}
document.body.innerHTML = `<div onclick="hello()">click me</div>`;
oc.window.show();
```
This is because all custom code is executed inside a &lt;script type=module&gt; so you need to make functions *global* if you want to access them from *outside* the module (e.g. in click handlers). So if you want to the above code to work, you should define the `hello` function like this instead:
```
```js
window.hello = function() {
console.log("hi");
}
Expand Down

0 comments on commit c8d63f1

Please sign in to comment.