Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Detect if mousedown inside a function

Posted on 2006-05-18
3
Medium Priority
?
1,021 Views
Last Modified: 2008-03-03
Is there anyway to detect mousedown inside of a javascript function?
0
Comment
Question by:johnywhite
3 Comments
 
LVL 3

Assisted Solution

by:Onyx23
Onyx23 earned 800 total points
ID: 16711250
If you want a document to capture events at all times while the document is loaded, you could execute the:

window.captureEvents(Event.MOUSEDOWN);

hope this helps
0
 
LVL 29

Accepted Solution

by:
Pravin Asar earned 1200 total points
ID: 16713595
Here is an example, which tracks the mouse event via only one function mH


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<script language="javascript">
function BrowserType () {
      var srchText = navigator.userAgent;
      var brwTypes = ("Opera,MSIE,Netscape,Firefox").split(',');
      for (var ix=0; ix < brwTypes.length; ix++) {
            if (srchText.toString().match(brwTypes[ix])) {
                  return brwTypes[ix];
            }
      }
      return null;
}

function mH(evt) {
      var brwType = BrowserType();
      var btn = null;
      if (!evt) { evt = window.event; }
      
      if (evt.type.match ('mousemove')) {
         window.status = 'X ' + evt.clientX + ' Y ' + evt.clientY;
            return;
      }
      if (evt.type.match('mouseup')) {
         window.status = 'Mouse Up';
            return;
      }

      switch (brwType) {
      case 'MSIE':
            btn = evt.button;
            break;
      case 'Netscape':
      case 'Firefox':
            btn = evt.which;
            break;
      default:
            btn = evt.button;
            break;
      }
      if (btn == 1) {
            window.status = evt.type + ' Left Button ';
      }
      else if (btn == 2) {
            window.status = evt.type + ' Right Button ';
      }
      else if (btn == 3) {
            window.status = evt.type + ' Right Button ';
      }
      
}
document.onmousedown = mH;
document.onmousemove = mH;
document.onmouseup = mH;

</script>
<textarea cols="40" rows="10">
</textarea>
</body>
</html>
0
 

Author Comment

by:johnywhite
ID: 16714090
Thanks that will do for what I need.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question