• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Java Script
 

Java Script

on

  • 3,758 views

Presentation delivered to magnet staff

Presentation delivered to magnet staff

Statistics

Views

Total Views
3,758
Views on SlideShare
3,755
Embed Views
3

Actions

Likes
0
Downloads
45
Comments
0

1 Embed 3

http://www.slideshare.net 3

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Java Script Java Script Presentation Transcript

    • JavaScript
    • With JavaScript,
      • A Web page can really react to what you're doing.
      • Images can swap when you move a cursor over them.
      • Form elements can influence each other on the fly.
      • And calculations can be made without having to resort to a CGI script.
      • There's none of this submit-and-wait stuff - everything happens on your Web page while you're playing with it.
    • Why JavaScript
      • One of the best things about JavaScript is that you can do a great deal with very little programming.
      • You don't need a fancy computer, you don't need any software other than a Web browser, and you don't need access to a Web server; you can do all your work right on your own computer.
      • Even though it's simple to work with, JavaScript is a complete programming language, so as you learn more complicated JavaScript, you're also learning the basics of computer programming. If you want to move on to other programming languages, like Perl, C, C++, or Java, JavaScript is a great introduction.
    • What is Java Script?
      • JavaScript is not Java.
      • Sometimes JavaScript isn't JavaScript! It turns out that different browsers deal with JavaScript differently.
      • View Source! The best way to learn JavaScript is to look at scripts other people have written. JavaScript, just like HTML, can be viewed by selecting View Source on your browser. Do it frequently!
      • Finally, as with HTML, the best way to learn JavaScript is to experiment freely and often.
    • JavaScript Syntax
      • JavaScript usually goes between the </title> tag and the </head> tag.
      • Like HTML, JavaScript is just text that can be typed into a word processor. It goes right into the HTML that describes your page. (Although I've only shown JavaScript in the header of the HTML page, you can also put JavaScript in the body. You'll see an example of this in the next lesson.)
      • The beginning of a bit of JavaScript begins with <script language=&quot;JavaScript&quot;>
    • Your First JavaScript Exercise
      • <HTML>
      • <HEAD>
      • <TITLE>
      • </TITLE>
      • <SCRIPT LANGUAGE = &quot;JavaScript&quot;> alert (&quot;Welcome to my Web Site&quot;); </SCRIPT>
      • </HEAD>
      • <BODY>
      • My first page with JavaScript Code.
      • </BODY>
      • </HTML>
    • Examples
      • alerts
        • <A HREF=&quot;javascript:alert('Hello World')&quot;>Hello World</A>
        • <A HREF=&quot;javascript:alert('Hello World');alert('Hello Net')&quot;>Hello World</a>
      • Variables
        • var monkey_love = prompt(&quot;Do you love the monkey?&quot;,&quot;Type yes or no&quot;);
        • if (monkey_love == &quot;yes&quot;)
        • {
        • alert(&quot;Welcome! I'm so glad you came! Please, read on!&quot;);
        • }
      • Events
        • <a href=&quot;#&quot; onClick=&quot;alert('Ooo, do it again!');&quot;>Click on me!</a>
        • <a href=&quot;#&quot; onMouseOver=&quot;alert('Hee hee!');&quot;>Mouse over me!</a>
    • MouseOver
      • One of the most commonly used features of JavaScript is the ability to change images on a mouseover.
        • <img src=&quot;thumbs_up1.gif&quot; name=&quot;the_image&quot;>
        • <a href=&quot;#&quot; onMouseOver=&quot;document.the_image.src='thumbs_up2.gif';&quot;> Change </a>
      • This is just like a standard <img src= > tag except this one has been given a name: the_image . This name could be anything: my_image, a_box, whatever - but it can't have any spaces in it.
    • Introduction to Window Manipulation
      • Before learning how to open a window in JavaScript, you should know how to open one using HTML. The HTML used to do this is:
      • <a href=&quot;yer_new_window.html&quot; target=&quot;yer_new_window&quot;>this link</a>
      • The important thing to know about windows opened by targeted links is that the window above now has the name &quot;yer_new_window&quot; associated with it. If you have another href that uses &quot;yer_new_window&quot; as the target, and you haven't closed the window yet, whatever URL you put in that link will open in the original window.
      • The JavaScript syntax is:
      • window.open(&quot;URL&quot;,&quot;name&quot;,&quot;features&quot;);
      • And the code that will use the above syntax will look like this
      • <a href=&quot;#&quot; onClick=&quot;window.open('index.html','india');&quot;>
      • Here's a window named javascript_1</a>
    • Windows Features Part I
      • The third parameter of the window.open() method is a list of features that you'd like your window to have.
      • If you don't include this parameter at all, the window will contain all the features of a default browser window. However, if you specify any features in the third parameter, just those features will appear.
      • For example, if you write
      • window.open(&quot;some_url&quot;,&quot;window_name&quot;,&quot;location,menubar&quot;);
      • you'll get a window with just the location box (also called address bar - the place in your browser where you type in a URL) and a menu bar (File, Edit, etc.). Note that it's important that you don't put any spaces in the string.
      • Another example is
      • window.open(&quot;some_url&quot;,&quot;window_name&quot;,&quot;location,height=100,width=100&quot;);
      • This will open a window that is 100 pixels high and 100 pixels wide and has no features other than a location field.
    • Windows Features Part II
      • Here's a list of the features that you can include in the feature string:
      • Menubar
        • It includes File, Edit, and a few other items.
      • Status
        • This is the message bar at the bottom of your window.
      • Scrollbars
        • This allows scrollbars to appear when necessary. ·
      • Resizable
        • If resizable is listed, the window can be resized.
      • Width
        • The width of the window in pixels. ·
      • Height
        • The height of the window in pixels.
      • Toolbar
        • The browser toolbar, which contains the Back and Forward buttons.
      • Location
        • The address bar of a browser into which you can type URLs.
    • Exercise 1
      • <html>
      • <head>
      • <SCRIPT LANGUAGE = &quot;JavaScript&quot;>
      • var monkey_love = prompt (&quot;Do you love monkey?&quot;, &quot;Type Yes or No&quot;);
      • if (monkey_love == &quot;yes&quot;){
      • alert (&quot;Welcome! I am glad you came! Please, read on!&quot;);
      • }else {
      • alert (&quot;Go away&quot;);
      • }
      • </SCRIPT>
      • </head>
      • <body>
    • Exercise 2
      • <SCRIPT LANGUAGE = &quot;JavaScript&quot;>
      • // document.writeln(&quot;Your Name is &quot;, Your_Name);
      • </SCRIPT>
      • <P>
      • <a href=&quot;#&quot; onClick=&quot;alert('Ooo, do it again!');&quot;>Click on me!</a>
      • <P>
      • <a href=&quot;#&quot; onMouseOver=&quot;alert('Hee hee');&quot;>Mouse over me</a>
      • <P>
      • <a href=&quot;contact.html&quot; target=&quot;my_window&quot;>this link</a>
      • <p>
      • <a href=&quot;#&quot; onClick=&quot;window.open('testit.htm','my_window', 'scrollbars,resizable,location,height=100,width=100')&quot;;>Clcik here</a>
      • </body>
      • </html>
    • Exercise 3 - Where has that browser been?
      • <SCRIPT language=&quot;JavaScript&quot;> function cameFrom(where) {    if (!document.referrer && !where) return true;    else return (document.referrer.indexOf(where)>=0)    } if (cameFrom(&quot;domain1.com&quot;)) {    location.replace(&quot;newpage1.html&quot;);    } else if (cameFrom(&quot;domain2.com&quot;)) {    location.replace(&quot;newpage2.html&quot;);    } if (cameFrom(&quot;google.com&quot;)) {    alert(&quot;You found us!&quot;);    } else if (cameFrom(&quot;worstenemy.com&quot;)) {    location.replace(&quot;reprimand.html&quot;);    } else if (cameFrom()) {    alert(&quot;The wind blows where it will, and you hear the sound of it, but you do not know from whence it comes.&quot;)    }
      • </SCRIPT>
    • Hard Return in JScript
      • While hard returns are irrelevant to HTML parsing, hard returns mean a world of difference in JavaScript.
      • For comments you can use the C-style block comment ( /* .... */ )
      • Don’t use the single line comment set-off by two slashes ( // )
      • Because it will turn everything until the closing script tag ( </script> ) into a single long comment (and will probably cause an error in the script).
    • Inline JavaScript
      • <H1 onMouseOver=&quot;this.style.color='tan';&quot; onMouseOut=&quot;this.style.color='purple';&quot;>Mouse over me to see my over color. Then mouse out to see my out color.</H1>