Run ruby from javascript isn't work

Run ruby from javascript isn’t work. It’s happened when I put the code used to run Ruby inside Window.onload
The first time opening htmlDialog, the code is working properly but when I close the htmlDialog then reopen it . The code is not working.

My Javascript:

<script>
window.onload = (event) => {
	sketchup.puts_string("window onload")
};
</script>

My .rb file:

$dialog.add_action_callback("puts_string") { |action_context, string|
	puts string.to_s
}

How to make it work?
Thank you in advance!

Read the first sentence - the “Note:…” - in documentation: HtmlDialog #add_action_callback method.
__
DO NOT USE global variable!!!

3 Likes

Thanks a lot! I didn’t notice that note.