Dynamic script import in Javascript

Step 1:Create a file named javadomain.js and paste the below code,

functiononclickJava(){
document.writeln("My domain is java");
}

 

Step 2:Create a file named dotnetdomain.js and paste the below code,

functiononclickDotNet(){
document.writeln("My domain is DotNet");
}

 

Step 3: Create a file named dynamicjavascript.html and pasthe the below code,

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1">
<scriptid="h"type="text/javascript">
document.getElementById('J').src= 'javadomain.js';
var a ="File111";
</script>
<scriptid="w"type="text/javascript">
document.getElementById('D').src= 'dotnetdomain.js';
var a ="File222";
</script>
<title>Javadomain</title>
</head>
<body>
<form>
<inputid="J"type="button"value="Java"onclick="onclickJava()">
<inputid="D"type="button"value="DotNet"onclick="onclickDotNet()">
</form>
</body>
</html>

 

In the above program we are importing the javadomain.js file for Java button and dotnetdomain.js file for DotNet button.

 

Thanks for reading this post………..!!!

Leave a Reply