Java Script Lesson Java Script - Lesson 2                                       Instructor: Roseann Krane

A JavaScript script that displays a default message in the browser status bar when a user loads a web page may be created.

Event handlers: JavaScript is an event-driven language.

  • An event is a user or system action: JavaScript responds to an event by running its associated event handler code. The syntax of an event handler is:
    onEvent="code"
    The onLoad event handler is called when the browser finishes loading a page. This gives the user a chance to personalize a page at startup. The syntax of the onLoad event handler:
    onLoad="code"
    The onLoad event handler must be inserted in the HTML document's BODY tag. Or insert it in the FRAMESET tag of the page's parent frame document when working with multi-frame pages.

    JavaScript is an object-based scripting language. 

    window.defaultStatus uses standard dot notation (object.property) to denote the defaultStatus property of the window object.

    JavaScript scripts can be embedded or nonembedded. An embedded script is one that is located within an HTML tag. Example: 


    <BODY BGCOLOR="black" TEXT="white" onLoad="window.defaultStatus='Navigator Frame'"> 


    A nonembedded script is one that is located between <SCRIPT LANGUAGE="JavaScript"> .. tags. Example: 


    <SCRIPT LANGUAGE="JavaScript"> 
        var currDate = new Date() 
        var currDay = currDate.getDate() 
        var currMonth = currDate.getMonth() + 1 
        var currYear = currDate.getYear() currDateStr = currMonth + "/" + currDay + "/" + currYear 
    </SCRIPT> 


    Assignment -- Add the following to the body line of your web page:


    onLoad="window.defaultStatus='Welcome to my Web page!'"

    Questions: (E-mail the answers to your teacher.)

    1. What is the instruction called when a statement appears in the browser status bar? (onEvent or onLoad) Explain.
    2. Name three of the actions that can happen by an event call.
    3. Explain embedded script.
    END of Lesson.