Computer Science, asked by Sassa1628, 1 year ago

How to use the same JavaScript in multiple content pages?

Answers

Answered by MohamedYaseen
0

 

How to use the same JavaScript in multiple content pages?

I want to use the same JavaScript in multiple content pages. How can I achieve this? I have a js file and I want to use it on the web page.

  Follow  Answer  15

 

1Answer

Rahul Sharma

Answered on 11th Jan, 2018

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>

Similar questions