How to include a generic file that loads a lot of javascripts in the header of an HTML file
I have tried many ways and cannot figure out how to do this.
I am loading a number of external scripts into the header of many html files. Here's an example:
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" language="Javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>
<script type="text/javascript" src="http://www.wolfram.com/cdf-player/plugin/v2.1/cdfplugin.js"></script>
What's the best way to avoid having to copy and paste them over and over in every HTML file?
I couldn't put it all in one common.js file and include this as they already have it <script>
. those. I can not do it
<script src="common.js"></script>
Any ideas how to do this? maybe with jquery? (I don't know anything about this). Maybe this is related? Jquery load () html file containing JavaScript
thank
source to share
You can use the following commands multiple times in your common.js for each source you want to download. Just keep changing the value node.src
.
var node = document.createElement('script');
node.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js";
document.body.appendChild(node);
And you can choose where to add the script to body
ie document.body.appendChild(node);
or head
ie document.head.appendChild(node);
from html
source to share