gradio: gradio.HTML CAN NOT load my javascript
Describe the bug
I use gradio.HTML(‘xxx.html’) to load html.The script in this file can not be load.Please look at this example.
If U click this button.
Console will show:
So how can I load my JS?
Thanks for help!
I know can use gr.button(_js).
But if I wants to let it work when the web show.How do I implement this feature?
Such as:
(function { alert('show web site'); })
Is there an existing issue for this?
- I have searched the existing issues
Reproduction
test.html
<button id="btn_test" onclick="click_test()">BUTTON</button>
run.py
test= shared.html(“test.html”)
gr.HTML(test, elem_id=“test”)
Screenshot
No response
Logs
None
System Info
gradio==3.16.2
Severity
blocking all usage of gradio
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 18 (5 by maintainers)
In 4.0 this parameter is named
jswith no underscore.@hxu296 @JLWLL @ParisNeo
Here’s a solution that I’ve managed to find. Hope it helps!
It seems that people have gathered around this issue for adding custom JS to gradio. I can volunteer to make a PR to update the usage example is Blocks.load documentation to reflect the solution @pngwn provided. Do you think this is a good idea? @abidlabs
Yes sorry the code needs to be wrapped in a function, my mistake:
I’m having the same issues as it seems that my js is not running in the html so I’ve tried the above solutions but still get no result. I implemented the same simple code that creates an alert when clicking the “hello” button:
I’ve tried some variations but still don’t get it to work. If anyone has a clue, please let me know!
head = f"“”
<script async src="https://www.googletagmanager.com/gtag/js?id={google_analytics_tracking_id}"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){{dataLayer.push(arguments);}} gtag('js', new Date()); gtag('config', '{google_analytics_tracking_id}'); </script>“”"
with gr.Blocks(head=head) as demo: …demo code…