View Full Document


Unformatted text preview:

Intro to JavaScript ACM Webmonkeys UIUC 2010 What is JavaScript Javascript is a scripting language used primarily on the web for client side scripting Also used on Palm s WebOS for app development Has nothing to do with Java Loosely typed dynamically bound Supports objects and closures making it suitable for largerscale projects Client side scripting In the context of web apps Javascript is a client side language This means it runs in the web browser NOT on the server You cannot directly access your database or any files on your web server from JavaScript the way that PHP can You can communicate with the server via separate HTTP requests this is how AJAX etc work Always keep in mind that the code is running on the client s computer Do not expect it to be secure Browsers can execute arbitrary JS on your page JS is meant to improve usability and add fancy effects to your web pages interfaces One last note before we get started Not all browsers will have JavaScript enabled Plug ins like NoScript will block your scripts from running by default Bots from Google et al do not have JS enabled So if you re using JavaScript on your site make sure you have a degradation strategy for users without it If needed this can be Please enable JavaScript to view this page Adding JavaScript to your webpage To include a script on your webpage you need to add a script tag into the HTML The syntax of the script tag is script type text javascript JavaScript goes here script Or if you have an external JS file to include script type text javascript src path to file js script The script is evaluated by the browser when it is first encountered Triggering JavaScript from your page To call a JavaScript function you cannot call a script tag explicitly you must wrap your code in a function use one of two methods 1 A link a tag with an href of javascript myFunc a href javascript doThisStuff Click Here a 2 An event in any tag div onclick doThisStuff div button onclick callMyFunction blah Note that

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...

Join to view Intro to Java script and access 3M+ class-specific study document.

We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Intro to Java script and access 3M+ class-specific study document.


By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?