• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1025
  • Last Modified:

Detect if mousedown inside a function

Is there anyway to detect mousedown inside of a javascript function?
0
johnywhite
Asked:
johnywhite
2 Solutions
 
Curtis ShullFounderCommented:
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
 
Pravin AsarPrincipal Systems EngineerCommented:
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
 
johnywhiteAuthor Commented:
Thanks that will do for what I need.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now