Java Script Basics Donna J Kain Clarkson University
Java. Script Basics Donna J. Kain, Clarkson University
What it is Java. Script is • A tool you can use to make HTML pages more dynamic. • A scripting language with similarities to programming languages but not programming. • A client side component. • Object based Donna Kain Clarkson University
What it isn’t • A programming language – Though it has similarities to Java and C++ Donna Kain Clarkson University
What it can do • Instruct browser to display information (I. e. user’s browser type) • Make webpage appearance different depending on browser • Monitor user events and specify reactions (I. e. mouse overs) • Generate html for parts of pages • Modify a page in response to events (I. e. click to change page color) Donna Kain Clarkson University
What it can do • Check user input (I. e. in a form) • Replace and update parts of pages (I. e. current date and time; user history of browsing) • Change style and position of page elements dynamically (I. e. create moving layers that follow the user’s mouse) • Control windows • Create alerts and messages Donna Kain Clarkson University
How it works Java. Script • runs in the browser • is added to HTML pages • Within the head element of a page • Within the body element of a page Donna Kain Clarkson University
Conventions Script tags § <script language=“Java. Script”> Script goes here </script> § <script language=“Java. Script”> <!-Script goes here //--> (comment tags hide script from old browsers) </script> Java. Script is case sensitive Donna Kain Clarkson University
Conventions Functions and Arguments <script language=“Java. Script”> <!-document. write(“Here’s a script”) ; //--> </script> Document. write is a function § Document is a pre-defined object § Write is a pre-defined method § The dot connects the object and the method Donna Kain Clarkson University
Conventions You can create names for objects, functions, and variables in Java. Script. However, note that reserved words that have special junctions in Java. Script. <script language=“Java. Script”> <!-document. write(“Here’s a script”) ; //--> </script> Info in parentheses is an argument. The argument here is a string, which must be in quotation marks. Place a semi-colon after Java. Script statements Donna Kain Clarkson University
Do it/View it Create a simple HTML page with the basic HTML, head, title, and body elements. Place the Java. Script in the body of the page. § <script language=“Java. Script”> <!-document. write(“Here’s a script”) ; //your script// //--> </script> Donna Kain Clarkson University
- Slides: 10