JavaScript Wrap-up.

Slides:



Advertisements
Similar presentations
Essentials for Design JavaScript Level One Michael Brooks
Advertisements

The Web Warrior Guide to Web Design Technologies
JavaScript- Introduction. What it is and what it does? What it is? It is NOT Java It is NOT Server-side programming Users can see code It is a client-side.
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
Computer Science 103 Chapter 4 Advanced JavaScript.
JavaScript Lesson 1 TBE 540. Prerequisites  Before beginning this lesson, the learner must be able to… Create a basic web page using a text editor and/or.
Escaping Characters document.write(). Learning Objectives By the end of this lecture, you should be able to: – Recognize some of the characters that can.
Javascript and the Web Whys and Hows of Javascript.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
JavaScript is a client-side scripting language. Programs run in the web browser on the client's computer. (PHP, in contrast, is a server-side scripting.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
An Introduction to JavaScript By: John Coliton Tuesday, November 10, 1998 Center for Teaching and Learning.
Introduction to JavaScript CS101 Introduction to Computing.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
HTML JAVASCRIPT. CONTENTS Javascript Example NOSCRIPT Tag Advantages Summary Exercise.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
Review of HTML and CSS A (very) brief review of some key fundamentals to be aware of in IT-238.
Step 1: Starting an HTML Document: Right Click: new>text document.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Module 1 Introduction to JavaScript
Java Script Introduction. Java Script Introduction.
Moving away from alert() Using innerHTML Using an empty div section
Chapter 6 JavaScript: Introduction to Scripting
>> JavaScript: Location, Functions and Objects
JavaScript is a programming language designed for Web pages.
Introduction to Javascript
Key concepts of Computing
Donna J. Kain, Clarkson University
JavaScript Loops.
Retrieving information from forms
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript Part 2 Organizing JavaScript Code into Functions
Introduction to JavaScript
JavaScript Introduction
Understanding JavaScript and Coding Essentials
Your 1st Programming Assignment
Introduction to JavaScript
JavaScript – Part I Mendelsohn.
Events Comp 205 Fall 2017.
The Web Wizard’s Guide To JavaScript
T. Jumana Abu Shmais – AOU - Riyadh
Lect2 (MCS/BCS) Javascript.
Document Structure & HTML
JavaScript Overview By Kevin Harville.
© Hugh McCabe 2000 Web Authoring Lecture 12
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
Java Script Siddharth Srivastava.
JavaScript is a scripting language designed for Web pages by Netscape.
Introduction to Programming and JavaScript
CNIT 133 Interactive Web Pags – JavaScript and AJAX
CIS 136 Building Mobile Apps
JavaScript for Beginners
Introduction to JavaScript
Introduction to Web programming
A Few Notes on JavaScript
JavaScript Part 2 Organizing JavaScript Code into Functions
Retrieving information from forms
Introduction to scripting
Adios alert() Using innerHTML Using an empty section
Presentation transcript:

JavaScript Wrap-up

JS-Disabled Browsers – Part 1 It is fairly common for JS to be disabled Some people intentionally disable JS Some spyware / anti-virus apps disable JS Some devices (e.g. certain cellphones) can’t run JS To avoid errors in JS-disabled browsers, you must place your entire script inside HTML comments. The comment should begin (and end) just inside the <script> tags. (Note: Use HTML, not JS comments – they are not the same.) <script type=“text/javascript”> <!-- Begin hiding from non-JS Browsers.... JavaScript code.... etc end hiding --> </script>

JS-Disabled Browsers – Part 2 The <noscript> tag: If JS is important to your page, you should notify the user so that if they have a JS-disabled browser, they know that your page may not work correctly. Use the <noscript> tag This tag must be somewhere in the BODY of your document (i.e. inside <body> tags Text inside the <noscript> tag ONLY displays on browsers without scripting capabilities (such as JS-disabled browsers). This tag should be somewhere inside the <body> section. <noscript> This page works best with JavaScript-enabled browsers. </noscript>

JS-Disabled Browsers Summary of code that should be used in ALL of your JavaScripts: 1. Around all of your scripts (but inside <script> tag): <script> <!-- JavaScript code here... etc... --> </script> 2. Inside <body> section: <noscript>This page is best viewed using JavaScript.</noscript>

Placing and Invoking Functions <html> <head> <title>First JS</title> <script language="JavaScript"> function test( ) { document.write("Hello from inside the test function."); } function anotherTest( ) document.write("Hello from inside the anotherTest function. "); </script> </head> <body> <script> test( ); //invoking the ‘test’ function anotherTest( ); //invoking the ‘anotherTest’ function </body> </html> Placing and Invoking Functions Note that the functoions are inside <head> Functions are invoked by simply typing their name and providing any required arguments (later). Because invoking a function is also JS command, this command must also be placed inside a <script> tag. Functions can also be invoked from inside forms (eg. onClick…) - later

Review: There are two ways to invoke (execute) a JS Function In the last example, we invoked a function by connecting a button click to the function. <input type=“button” value=“Click Me!” onClick=“runSomeFunction()” /> Recall that you can also invoke a function by simply writing its name inside a <script> tag. While JS code is usually placed inside <head>, there are times when you may wish to include some JS inside <body>. To do so, you must notify the browser that you are temporarily not writing HTML, and are instead, writing script. <html> Welcome to my first web page. I hope you like it... <hr /> <script> runSomeFunction(); </script>

<html> <head> <title>First JS</title> <script language="JavaScript"> function greetUser( ) { document.write("<h1>Hello!!!!</h1>"); } </script> </head> <body> <form name="form1"> <input type="button" value="Greet Me!" onClick="greetUser( )" /> </form> </body> </html> <html> <head> <title>First JS</title> <script language="JavaScript"> function greetUser( ) { document.write("<h1>Hello!!!!</h1>"); } </script> </head> <body> <script> greetUser( ); </form> </body> </html>

Recap of Must-Dos Anticipate JS-disabled browsers Place scripts inside an HTML (not JS) comment Use the <noscript> tag Respect naming conventions for functions and variables: First word in lower case Subsequent words capitalized – no spaces Must avoid “reserved words” Any JavaScript reference (such as this one) will have a list of these reserved words. Your book has such a list on p. 111

Comments Possibly even more important in JS than in HTML. Recall that in HTML, comments are placed between <!-- and --> Comments in JS use // , /* */ Individual lines: Anything after // through to the end of that line of text is ignored. Multiple lines: Anything between /* and */ This can span multiple lines document.write("Hello World"); //This is ignored.... /* Everything inside here ... .... .... is also ignored. */