Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript Introduction inf385t Semantic Web 2/20/2006.

Similar presentations


Presentation on theme: "JavaScript Introduction inf385t Semantic Web 2/20/2006."— Presentation transcript:

1 JavaScript Introduction inf385t Semantic Web 2/20/2006

2 What is Javascript? Scripted Programming Language Cannot run standalone. Embedded is most web browsers. Often used to create web pages that respond dynamically to user action. Also used for server side development.

3 History Need for client side interaction. First developed by Netscape. Later purchased by Sun. Not related to the Java Programming Language. Not quite the same as Microsoft’s JScript.

4 Document Object Model A framework to describe a web page (document) in a tree-like structure. Specs: http://www.w3.org/TR/REC-DOM-Level-1/ http://www.w3.org/TR/REC-DOM-Level-1/

5 Application Programming Interface The DOM is accessed through the API. The official client-side API documentation is here: http://docs.sun.com/source/816-6408-10/

6 Getting Started Usually goes between and tags. Code is also put inside HTML comments Web Page <!-- html comment // code goes here // -->

7 Variables <!-- html comment var x = 15; var _y = x * 10; var name = prompt("What is your name?"); // -->

8 Modifying a document http://docs.sun.com/source/816-6408-10/document.htm <!-- html comment document.write("<a href=\""); document.write(document.referrer); document.write("\">Return to the last page "); // -->

9 Formatting Strings Strings have methods that modify the way they are printed. http://docs.sun.com/source/816-6408-10/string.htm <!-- html comment var name = prompt("What is your name? "); document.writeln(name.fontcolor("red")); document.writeln(name.italics()); document.writeln(name.toUpperCase()); // -->

10 Functions <!-- html comment function foo(name) { document.writeln(name.bold()); } // -->

11 More Programming Constructs if if(var1==var2) {/* do stuff */ } for loops for(i=0; i < count; i++) {/* do stuff */ } while loops while(var1==var2) {/* do stuff */ } arrays var a = new Array(1, 2, 3); document.writeln (a[0]);

12 Interaction Link and image elements have special properties that use the definitions set up in the main block. http://docs.sun.com/source/816-6408-10/handlers.htm Click me change

13 Forms http://docs.sun.com/source/816-6408-10/form.htm http://docs.sun.com/source/816-6408-10/text.htm <input type="text" name="name" size="40" value="Enter your name" onFocus="foo();" onChange="foo();" > document.form1.name.value = "John"; document.form1.name.focus();

14 Sorting a Table http://www.cs.utexas.edu/~oursland/inf385t/sorttable.html

15 Learning from Others Client-side Javascript can be viewed by looking at the source code for a page. Consider this function from the Google homepage. <!-- function qs(el) { if (window.RegExp && window.encodeURIComponent) { var ue=el.href; var qe=encodeURIComponent(document.f.q.value); if(ue.indexOf("q=")!=-1) { el.href=ue.replace(new RegExp("q=[^&$]*"),"q="+qe); } else { el.href=ue+"&q="+qe; } } return 1; } // -->

16 Applications Shadows Bookmarklet –http://www.shadows.com/features/tcr.htmhttp://www.shadows.com/features/tcr.htm Google Maps –http://maps.google.com/http://maps.google.com/ Gmail –http://gmail.com/http://gmail.com/ Flickr –http://flickr.com/http://flickr.com/ Del.icio.us –http://del.icio.us/http://del.icio.us/ Tecnorati –http://technorati.com/http://technorati.com/ Digg –http://digg.com/jshomepageedithttp://digg.com/jshomepageedit


Download ppt "JavaScript Introduction inf385t Semantic Web 2/20/2006."

Similar presentations


Ads by Google