JavaScript Get all Loaded Scripts [duplicate]

。_饼干妹妹 提交于 2019-12-06 01:52:34

问题


I am trying to create a Javascript function that will return all javascript files loaded. For Example:

I load jquery.js, jquery.somescript.js, and tinymce.js

I want a function to return everything in script format (so if I were to save and run the return text again) it would work just as if I had called the files described above. Also if TinyMCE loads 15 JS fies, it should return as well.

I hope that isn't too confusing to understand, but any help would be greatly appreciated!

Thanks in Advance!


回答1:


getElementsByTagName should get you started:

var scripts = document.getElementsByTagName('script');
// TODO: loop and read the src attribute



回答2:


I am not sure exactly what you are trying to do but it sounds as if you are wanting one .js file to instead of many. I think you would be making more work for yourself to do that in a script. Just view the source for all of the script files and append then to one file. Save that then call that file as your src.



来源:https://stackoverflow.com/questions/3160609/javascript-get-all-loaded-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!