瀏覽代碼

add logic to remove all script of current page before moving to new page

namnguyen 4 月之前
父節點
當前提交
50790ce159
共有 1 個文件被更改,包括 6 次插入8 次删除
  1. 6 8
      frontend/taipy-gui/src/components/pages/TaipyRendered.tsx

+ 6 - 8
frontend/taipy-gui/src/components/pages/TaipyRendered.tsx

@@ -64,15 +64,13 @@ const setStyle = (id: string, styleString: string): void => {
 
 // set script tag for the page
 const setScript = (id: string, scriptPaths: string[]): void => {
+    document.querySelectorAll(`script[id^="${id}_"]`).forEach(script => script.remove());
     scriptPaths.forEach((path, index) => {
-        let script = document.getElementById(`${id}_${index}`) as HTMLScriptElement | null;
-        if (!script) {
-            script = document.createElement("script");
-            script.id = `${id}_${index}`;
-            script.src = path;
-            script.defer = true;
-            document.head.append(script);
-        }
+        const script = document.createElement("script");
+        script.id = `${id}_${index}`;
+        script.src = path;
+        script.defer = true;
+        document.head.append(script);
     });
 };