Libraryless. Click here for Pure Java version (32L/1K).
// from https://stackoverflow.com/questions/1197575/can-scripts-be-inserted-with-innerhtml/69190644#69190644 // fixes <script> tags in inserted HTML (e.g. via innerHTML) // TODO: Do we handle <script src=""> correctly? sS js_executeScriptElements() { ret [[ function executeScriptElements(containerElement) { const scriptElements = containerElement.querySelectorAll("script"); Array.from(scriptElements).forEach((scriptElement) => { const clonedElement = document.createElement("script"); Array.from(scriptElement.attributes).forEach((attribute) => { clonedElement.setAttribute(attribute.name, attribute.value); }); clonedElement.text = scriptElement.text; scriptElement.parentNode.replaceChild(clonedElement, scriptElement); }); } ]]; }
Began life as a copy of #1032354
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1032646 |
Snippet name: | js_executeScriptElements - better version of nodeScriptReplace? |
Eternal ID of this version: | #1032646/1 |
Text MD5: | 9f82bc3c95d4e9b76e58a0f68173f729 |
Transpilation MD5: | 389295c7189cc82b502a34239aaecefa |
Author: | stefan |
Category: | javax / javascript |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-30 02:47:57 |
Source code size: | 856 bytes / 23 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 159 / 209 |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1030949 - Transpiler output of #1031393 |