Is there any simple way to add or link external javascript file into all .html files in directory by java script.
I have a folder called src in that there are n-number of .html files are available. I need to provide <script src="event_listener.js"></script> manually in each .html files, I'm looking for automate this step by javascript. So far I tried by reading a file like below,
$.get(path_of_the_file, function( my_var ) {
console.log(my_var)
}, 'html');
But I'm having cross-domain issue. So i'm unable to achieve the same.
I'm new to javascript. So I don't have an idea to solve this issue. If I have this problem in python I could try something like below,
import os
file_path=os.listdir('path_of_the_files')
for file_ in file_path:
if file_.endswith('.html'):
fo=open(file_path+'/'+file_,'r')
i=0
lines=fo.readlines()
for line in lines:
if line.strip().startwith("</html>"):
el=i
break
i+=1
lines.insert(["<script src="event_listener.js"></script>"],i)
fo.close()
fo=open(file_path+'/'+file_,'w')
fo.writelines( lines )
At the worst case I could try with python.
But I hope this could be solved by without moving to python.
Thanks in Advance.