File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 6666 .then(html => {
6767 // Set the current document's HTML to the fetched content
6868 document.documentElement.innerHTML = html;
69+ // After setting `elm.innerHTML = ...`, run scripts manually
70+ elm.querySelectorAll('script').forEach(oldScript => {
71+ const newScript = document.createElement('script');
72+ // copy over all attributes (e.g. src, type, async, etc.)
73+ for (const { name, value } of oldScript.attributes) {
74+ newScript.setAttribute(name, value);
75+ }
76+ // copy inline code or fallback to src-based loading
77+ newScript.textContent = oldScript.textContent;
78+ // replace the old <script> so the browser will actually execute it
79+ oldScript.replaceWith(newScript);
80+ });
81+
6982 })
7083 .catch(error => {
7184 console.error('There was a problem with the fetch operation:', error);
You can’t perform that action at this time.
0 commit comments