Importing Js file in Html Example

Javadomain.js: [Js file]

function alertMe(){
alert("Hello Javadomain.in");
}

Import.html

<html>
<head>
<script type="text/javascript" src="Javadomain.js" >
</script>
</head>
<body onload="alertMe();">
</body>
</html>

What we did:

1. We have written a javascript file named javadomain.js which contains a method called alertMe, which prints Hello Javadomain.in

2. Now this method is imported in Import.html file using src attribute of script tag. you can refer the highlighted line above.

3. We have called the alertMe() method from body onload method.

490 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *