We can achieve this using javascript or using jquery.Below methods demonstrate it.
Method 1: Use any JavaScript to include another js file.
Step 1: Add following function in your page.
function includeScript(url)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
}
Step 2: Now call the below includeScript function, Where you want to include the js file .
includeScript('/js/jquery-1.7.min.js');
Other method is:-
Method 2: Use jQuery to include another js file .
Step 1: Add jQuery File in your webpage like this.
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
Step 2: Just call the includeScript function like below code.
jQuery(document).ready(function(){
$.includeScript('/js/jquery-1.7.min.js');
});
0 Comment(s)