我使用Ajax包含页面,但我还需要包含各自的javascript文件,这需要同时从内存中删除以前的javascript文件.
如何卸载当前加载的javascript文件(以及它们在内存中的代码),以便我可以加载新页面的文件?它们很可能会发生冲突,因此加载了多个独立文件的javascript文件.
Not*_*tMe 12
这听起来像你需要重新评估你的设计.您需要删除ajax,或者您不需要在方法名称中发生冲突.
您可以查看以下链接:http://www.javascriptkit.com/javatutors/loadjavascriptcss2.shtml
其中提供了有关如何从DOM中删除javascript的信息.但是,现代浏览器会将代码留在浏览器的内存中.
可以卸载 javaScript 文件,从浏览器中清除整个代码。步骤是:
例子
mainJs = document.getElementById("mainJs");
document.head.removeChild(mainJS);//Remooves main.js from the DOM tree
flushFile = document.createElement("script");
flushFile.setAttribute("src", "flush.js");
document.head.appendChild(flushFile);//Loads flush.js into the DOM tree, overwriting all functions and variables of main.js in browser memory to null
Run Code Online (Sandbox Code Playgroud)
就是这样
| 归档时间: |
|
| 查看次数: |
34452 次 |
| 最近记录: |