How to Access Functions Within an External JS File
- 1). Right-click the HTML file where you want to call the external Javascript functions. Click "Open With" and select your preferred HTML editor from the list. Click "Open" to edit the code.
- 2). Type the following code within the "<head>" and "</head>" HTML tags:
<SCRIPT language="JavaScript" SRC="http://www.domain.com/externalfile.js"></SCRIPT>
Replace the "domain" with your own domain, and replace the "externalfile.js" text with your own file name. You can also link to external JS files on another domain. - 3). Scroll down the HTML file to the location of the element where you want to call the JS function. Type the JS function code in the element. For instance, if you want to call a function when a user clicks a button, the following code calls "myfunction" in the external file linked earlier:
<input type="button" onClick="javascript: myfunction()" /> - 4). Click "Save" to save the code changes. To view the tested code, open the page in a Web browser. The Javascript function executes when you click an element on your page.