Site icon NgDeveloper

Importing Js file in Html Example

Javadomain.js: [Js file]

[html]
function alertMe(){
alert("Hello Javadomain.in");
}
[/html]

Import.html
[html highlight=”3″]
<html>
<head>
<script type="text/javascript" src="Javadomain.js" >
</script>
</head>
<body onload="alertMe();">
</body>
</html>
[/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.

Exit mobile version