Tạo file JavaScript ngoài với đuôi .js. Sau đó thêm vào file HTML trong thẻ script. Thuộc tính src dùng nhúng file JS ngoài.
Nếu nhiều file JS ngoài, thêm vào cùng trang để tăng hiệu năng.
Giả sử new.js là file JS ngoài:
function display() { alert("Hello World!"); }Thêm file JS ngoài vào trang HTML:
<html> <body> <form> <input type="button" value="Result" onclick="display()"/> </form> <script src="new.js"> </script> </body> </html>