70 likes | 162 Views
Using External JavaScript Documents. Instructor: Joseph DiVerdi, Ph.D., MBA. Several Places To Keep Scripts. Reference Internal Script. <!DOCTYPE HTML PUBLIC ... > <HTML> <HEAD> <TITLE>Today's Date</TITLE> <SCRIPT TYPE="text/javascript"> function print_date() {
E N D
Using External JavaScript Documents Instructor: Joseph DiVerdi, Ph.D., MBA
Reference Internal Script <!DOCTYPE HTML PUBLIC ... > <HTML> <HEAD> <TITLE>Today's Date</TITLE> <SCRIPT TYPE="text/javascript"> function print_date() { var my_date = new Date(); document.write(my_date.toLocaleString()); } </SCRIPT> </HEAD> <BODY> The current date and time are: <SCRIPT TYPE="text/javascript">print_date();</SCRIPT> </BODY> </HTML>
Reference External Script <!DOCTYPE HTML PUBLIC ... > <HTML> <HEAD> <TITLE>Today's Date</TITLE> <SCRIPT TYPE="text/javascript" SRC="/~diverdi/my_script.js"> </SCRIPT> </HEAD> <BODY> The current date and time are: <SCRIPT TYPE="text/javascript"> print_date(); </SCRIPT> </BODY> </HTML>
Display Current Time & Date • Requires Function Definition • Uses External JavaScript Document • Create javascript Directory in html Directory • Create file my_script.js in javascript • Include Function in my_script.js
Contents of my_script.js // simple function definition function print_date() { var my_date = new Date(); document.write(my_date.toLocaleString()); } • Note That This File Contains No HTML