Computer >> Computer tutorials >  >> Programming >> Javascript

How to use the same JavaScript in multiple content pages?


To use the same JavaScript in more than one page, add the js code in an external JavaScript file. Let’s say the following demo.js is our external JavaScript file −

function display() {
   alert("Hello World!");
}

Now add the external JavaScript file to the following HTML web page. In the same way, you can add it to multiple content page.

<html>
   <body>
      <form>
         <input type="button" value="Result" onclick="display()"/>
      </form>
      <script src="demo.js">
      </script>
   </body>
</html>