পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Wednesday, March 8, 2017

Prototype - Event Handling

Event management is one of the biggest challenges to achieve cross-browser scripting. Every browser has different approaches to handle key strokes.
Prototype Framework handles all cross browser compatibility issues and keeps you free from all trouble related to event management.

Prototype Framework provides Event namespace, which is replete with methods, that all take the current event object as an argument, and happily produce the information you're requesting, across all major browsers.
Event namespace also provides a standardized list of key codes you can use with keyboard-related events. The following constants are defined in the namespace −
S.No. Key Constant & Description
1. KEY_BACKSPACE
Represent back space key.
2. KEY_TAB
Represent tab key.
3. KEY_RETURN
Represent return key.
4. KEY_ESC
Represent esc key.
5. KEY_LEFT
Represent left key.
6. KEY_UP
Represent up key.
7. KEY_RIGHT
Represent right key.
8. KEY_DOWN
Represent down key.
9. KEY_DELETE
Represent delete key.
10. KEY_HOME
Represent home key.
11. KEY_END
Represent end key.
12. KEY_PAGEUP
Represent page up key.
13. KEY_PAGEDOWN
Represent page down key.

How to Handle Events

Before we start, let us see an example of using an event method. This example shows how to capture the DOM element on which the event occurred.

Example

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         // Register event 'click' and associated call back.
         Event.observe(document, 'click', respondToClick);
  
         // Callback function to handle the event.
         function respondToClick(event) {
            var element = event.element();
            alert("Tag Name : " + element.tagName );
         }
      </script>
   </head>

   <body>
      <p id = "note"> Click on any part to see the result.</p>
      <p id = "para">This is paragraph</p>
      <div id = "division">This is divsion.</div>
   </body>
</html>

Output

Here is a complete list of all the methods related to Event. The functions you're most likely to use a lot are observe, element and stop.

Prototype Event Methods

NOTE − Make sure you at least have the version 1.6 of prototype.js.
S.No. Method & Description
1. element() Returns the DOM element on which the event occurred.
2. extend() Extends the event with all of the methods contained in Event.Methods.
3. findElement() Returns the first DOM element with a given tag name, upwards from the one on which the event occurred.
4. isLeftClick() Determines whether a button-related mouse event was about the "left" (primary, actually) button.
5. observe() Registers an event handler on a DOM element.
6. pointerX() Returns the absolute horizontal position for a mouse event.
7. pointerY() Returns the absolute vertical position for a mouse event.
8. stop() Stops the event's propagation and prevents its default action from being triggered eventually.
9. stopObserving() Unregisters an event handler.
10. unloadCache() Unregisters all event handlers registered through observe. Automatically wired for you. Not available since 1.6.

No comments:

Post a Comment