How to add javascript into output?

my code as follow:

from pyrevit import script

output = script.get_output()
html = '<script>' \
        'function myFunction() {' \
        'document.getElementById("demo").style.color = "red";' \
        '}' \
        '</script>'
output.print_html(html)

output.print_html("<h3 id='demo' onclick='myFunction()'>Click me to change my color.</h3>")

but it happens:
image

Not too confident with using js in the pyrevit output window. But perhaps it has something to do with how it handles the page being appended with data.
Have you tried joining the script html and the h3 html into a single string to print?

I was not sure it was possible, so it got me starting. I am always stunned by all the stuff prebuild in pyRevit
Check this out:

from pyrevit import script

output = script.get_output()

output.inject_script('function myFunction() {document.getElementById("demo").style.color = "red";}', body=False)
output.print_html("<h3 id='demo' onclick='myFunction()'>Click me to change my color.</h3>")

and it does not even give you the javascript warning this way

@davidvadkerti something I am sure you will like to fix the js warning popup of model checker

2022-07-01_13-40-20

2 Likes