JavaScript
  Home arrow JavaScript arrow Page 4 - Understanding The JavaScript Event Mod...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Understanding The JavaScript Event Model (part 1)
By: Team Melonfire, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 35
    2002-06-25

    Table of Contents:
  • Understanding The JavaScript Event Model (part 1)
  • Popeye() And Olive()
  • Handling Things
  • Red Alert
  • Mouse Hunt
  • Forty Two
  • Flavour Of The Month
  • Linking Up
  • Game Over

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Understanding The JavaScript Event Model (part 1) - Red Alert
    (Page 4 of 9 )

    The "document" object refers to the document body, or the Web page itself. When this page loads into the Web browser (or when the browser leaves a page for a new one), an event is triggered, which may be captured and processed by appropriate JavaScript.

    Here's a quick example, which pops up a dialog box when the page has finished loading.
    <html>
    <head>
    <script language="JavaScript">
    function redAlert() 
    {
    alert("Page successfully loaded");
    }
    </script>
    </head>
    <body onLoad="redAlert()">
    </body>
    </html>
    The onLoad and onUnload event handlers for the "document" object are usually placed in the <body> tag. Once the page has finished loading, the onLoad handler is triggered, the redAlert() JavaScript function is invoked and an alert box is generated.

    You can also run a function when the user leaves a Web page with the onUnload handler - as the following example demonstrates:
    <html>
    <head>
    <script language="JavaScript">
    function redAlert() 
    {
    confirm("Are you sure you want to leave this Web page?");
    }
    </script>
    </head>
    <body onUnload="redAlert()">
    </body>
    </html>
    onLoad and onUnload can be used individually, or together.

    In order to simplify the entire process and save time, you can place JavaScript code within the event handler invocation itself - as the following rework of the example above demonstrates:
    <html>
    <head>
    </head>
    <body onLoad="javascript:alert('This is simpler, right?')"> </body>
    </html>
    Yes, it is. Though only so long as you have a couple of lines of code to be executed - anything more complicated, and you're better off putting it into a function.

    More JavaScript Articles
    More By Team Melonfire, (c) Melonfire


     

       

    JAVASCRIPT ARTICLES

    - Getting Attention with Interactive Effects
    - Interacting with Tooltips and Previews
    - Just-in-Time Information and Ajax
    - Interactive Effects
    - Using Cookies With JavaScript
    - Understanding the JavaScript RegExp Object
    - Controlling Browser Properties with JavaScri...
    - Using Timers in JavaScript
    - Form Validation with JavaScript
    - JavaScript Exception Handling
    - Stringing Things Along
    - Understanding The JavaScript Event Model (pa...
    - Understanding The JavaScript Event Model (pa...
    - An Object Lesson In JavaScript




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway