inner_html containing script tag breaks page
See original GitHub issueThe following example should insert a script tag into a div:
import justpy as jp
wp = jp.WebPage()
d = jp.Div()
d.inner_html = '<script>alert("Hello World!");</script>'
wp.add(d)
jp.justpy(lambda: wp)
But the result is a page full of JavaScript code. It looks like the closing </script>
causes the the remaining code of the JustPy framework to be interpreted as HTML.
Although I’m aware of other possibilities to insert code into the HTML body (e.g. body_html
), this smells like unsafe behavior. Besides, it would be handy to be able to just insert any HTML via inner_html
.
Issue Analytics
- State:
- Created a year ago
- Comments:9
Top Results From Across the Web
Can scripts be inserted with innerHTML? - Stack Overflow
Note: script elements inserted using innerHTML do not execute when they are inserted. But beware, this doesn't mean innerHTML is safe from cross-site...
Read more >Run script tags in innerHTML content - Ionuț Colceriu
When inserting HTML content in the DOM using innerHTML, script tags inside it will not load or run. This applies to both inline...
Read more >JavaScript HTML DOM - Changing HTML - W3Schools
The HTML DOM allows JavaScript to change the content of HTML elements. ... DOM to get the element with id="p1"; A JavaScript changes...
Read more >The Curious Case of document.write - Eager Blog
document.write is weird. It inserts HTML into the page wherever it appears. Well, it inserts its HTML directly after the script tag it...
Read more >Element.innerHTML - Web APIs | MDN
The innerHTML property can be used to examine the current HTML source of the page, including any changes that have been made since...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is interesting: https://www.danielcrabtree.com/blog/25/gotchas-with-dynamically-adding-script-tags-to-html Apparently htnl5 does not execute scripts inserted via innerHtml
Perhaps the solution is to wait for page_ready and then run a JavaScript script that inserts the wanted script not using inner html.
See #473 and #471 - i suggest we allow user specific java code to be explicitly loaded as part of the startup process. That will be way cleaner than having to fiddle with html as such. Especially debugging the java script code and setting break points will be way easier.