Home arrow JavaScript arrow Page 2 - OnLoad and OnMouse JavaScript Events
JAVASCRIPT

OnLoad and OnMouse JavaScript Events


In our last article we left off with the OnKeyUp function, which is triggered when a user releases a key on the keyboard. We will continue discussing the various JavaScript events in this article, and hopefully finish them in the next tutorial. So grab yourself some coffee and let’s get to work.

Author Info:
By: James Payne
Rating: 3 stars3 stars3 stars3 stars3 stars / 14
December 10, 2007
TABLE OF CONTENTS:
  1. · OnLoad and OnMouse JavaScript Events
  2. · OnMouse Events
  3. · OnMouseMove
  4. · OnMouseOut
  5. · OnMouseOver
  6. · OnMouseUp

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
OnLoad and OnMouse JavaScript Events - OnMouse Events
(Page 2 of 6 )

OnMouse events trigger based upon the user's mouse clicks. There are five in total, starting with the OnMouseDown event.

OnMouseDown

An OnMouseDown event is triggered when the user clicks a mouse button. In the following example, we create a program that will trigger a pop-up alert box to tell the user which element they are clicking on.


<html>

<head>

<script type="text/javascript">

function dontclickme(e)

{

var click

if (!e) var e = window.event

if (e.target) click = e.target

else if (e.srcElement) click = e.srcElement

if (click.nodeType == 3)

click = click.parentNode

var tname

tname=click.tagName

alert("Quit clicking on my " + tname + " element!")

}

</script>

</head>


<body onmousedown="dontclickme(event)">


<h1>Don't you dare click me!</h1>

<p>You may have clicked on the header...but you better not click here!</p>

<input type="submit" value="Click and you will get what for!">


</body>


</html>

In the above example if the user clicks on the phrase “Don’t you dare click me!”, a pop-up will appear with the following text: "Quit clicking on my H1 element!"

If they click on the phrase “You may have clicked on the header…but you better not click here!”, a pop-up will appear, saying: "Quit clicking on my P element."

Lastly, if the user clicks on the submit button, the text "Quit clicking on my Input element!" will appear in a pop-up alert.

A good use for this is if you have a bunch of photos on your site that you don’t want users to be able to download or copy. Simply set the trigger event on each photo with a pop-up alert telling them the images are copyright protected. When they try to save the pictures a pop-up will appear and they will find they are unable to do so.

Supporting HTML tags: <a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>, <caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>, <li>, <map>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>

Supporting Javascript objects: button, document, link


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials