Home-Assistant-Lovelace-HTML-Jinja2-Template-card
Home-Assistant-Lovelace-HTML-Jinja2-Template-card copied to clipboard
<script> in custom:html-template-card
Is this the best place to ask questions re: this card? Please advise otherwise...
I have the following:
type: 'custom:html-template-card'
content: >
<script>function hello() {alert('hi there');}</script>
<button onclick="hello();"> O </button>
When I click the button nothing happens... Can I use javascript functions defined in
More specifically, I am needing to do these two things (among many others):
- Popup up an mp4 video when a preview image is clicked.
- Change the value of an input_text to refer to the "next" motion event image.
Thanks for your help!
Unfortunately as far as I know it's not possible to use scripts in content. You can try to use picture-elements + browser mod to create a popup.
You say, "as far as you know". You mean there is something outside your custom card which prevents it? I.e., it could not be done by any card?
P.S. Calling onclick='alert("hello")' works... ...just can't define/call a user defined function.
Well, I am not an expert, but technology that is used in this card doesn't seem to like <script>
in content, plus there is no access to HA functions from scripts created in context. It's possible that is doable, but I don't know how to do it ;)
I was thinking of using the ha api for access to services... In fact, I might be able to do some things with href. I'll post any success...
Is the
it can be really hard to keep straight when writing server-side script which generates client-side script ;-)
@donburch888 it is passed to the browser
I found out that you actually can run a script, for example in image onLoad. Here I'm using a dummy image.
<img onLoad='
alert("Hello World!")
' src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" />