Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

cursor position within  FRAMESET problem

Posted on 2001-08-08
5
Medium Priority
?
244 Views
Last Modified: 2013-11-19
I am trying to get the cursor position within the window that I open using a bookmarklet.  The window comprises of 3 frames -- top, left and right.  I want the cusor position when in the right frame.
The frameset is:
<FRAMESET rows "35,*" name = "fs1">
  <FRAME src ="top.htm" name ="top">
<FRAMESET cols "*,135" name = "fs2">
     <FRAME src ="left.asp" name ="left">
     <FRAME src ="right.htm" name ="main">
</FRAMESET>
</FRAMESET>
Can someone please tell me how to do it?
0
Comment
Question by:Chris_m
  • 3
5 Comments
 
LVL 14

Expert Comment

by:avner
ID: 6364062
add to the body element :
<body onmousemove="aa()">

and then create the aa function , that will take the x,y property :
function aa()
{
xPos=window.event.clientX
yPos=window.event.clientY
alert(xPos+" "+yPos)
}

Something like that.
0
 
LVL 1

Accepted Solution

by:
labcoat earned 200 total points
ID: 6366651
Above example is ok, but NEVER put an alert into on onmousemove. Think of how many alerts you will get! :-)
Instead, try (for testing) using the status bar. Also, I added browser compatability (ns4+, ie5+, mozilla 0.8+)

--labcoat

<!-- BEGIN CODE --

<html>
<head>
    <title>Mouse Coords</title>
    <script language="JavaScript">
    <!--//
    var oDoc=document; // global variable reference to the document
   
    // browser checking
    var bDOM=Boolean(oDoc.getElementById);
    var bIE=Boolean(oDoc.all), bNS=!Boolean(bIE);
    var bIE5=Boolean(bIE && bDOM), bNS6=Boolean(bNS && bDOM);
    var bIE4=Boolean(bIE && !bDOM), bNS4=Boolean(bNS && !bDOM);
   
    function handleMouseMove(e) {
        var nX, nY;
        if (bIE) e=event, nX=e.clientX, nY=e.clientY;
        else if (bNS4) nX=e.x, nY=e.y;
        else if (bNS6) nX=e.layerX, nY=e.layerY;
        status=nX+', '+nY;
    }
    onload=function() {
        if (bNS4) document.captureEvents(Event.MOUSEMOVE);
        document.onmousemove=handleMouseMove;
    }
    //-->
    </script>
</head>
<body>
</body>
</html>

-- END CODE -->
0
 

Expert Comment

by:dolithe
ID: 7250708
I have looked at the example offered above and it looks like it should do what I want but is there someway to limit the mouse activity to only register when I move the mouse over a specific <div> and not the whole document?
0
 
LVL 1

Expert Comment

by:labcoat
ID: 7251891
dolithe ,

In short, yes.

<!--//BEGIN CODE EXAMPLE//

// CHANGE THE FOLLOWING BLOCK OF CODE
onload=function() {
   if (bNS4) document.captureEvents(Event.MOUSEMOVE);
   document.onmousemove=handleMouseMove;
}

// TO THE FOLLOWING
function getDivById(sId) {
    if (bIE) return document.all[sId];
    else if (bNS4) return document.layers[sId]; // this won't get nested divs
    else if (bNS6) return document.getElementById(sId)
    else return null;
}
onload=function() {

   if (bNS4) document.captureEvents(Event.MOUSEMOVE);
   document.onmousemove=handleMouseMove;
}

//END CODE EXAMPLE//-->
0
 
LVL 1

Expert Comment

by:labcoat
ID: 7251903
Sorry, some how the last comment got submitted before I was finished.

<!--//BEGIN CODE EXAMPLE//

// CHANGE THE FOLLOWING BLOCK OF CODE
onload=function() {
  if (bNS4) document.captureEvents(Event.MOUSEMOVE);
  document.onmousemove=handleMouseMove;
}

// TO THE FOLLOWING
function getDivById(sId) {
   if (bIE) return document.all[sId];
   else if (bNS4) return document.layers[sId]; // this won't get nested divs
   else if (bNS6) return document.getElementById(sId)
   else return null;
}
onload=function() {
  var oDivToCapture = getDivById('PUT_DIV_TO_CAPTURE_ID_HERE');
  if (bNS4) oDivToCapture.captureEvents(Event.MOUSEMOVE);
  oDivToCapture.onmousemove=handleMouseMove;
}

//END CODE EXAMPLE//-->

You also might need to modify the handleMouseMove function a little, depending on what type of coords you want. For example, do you want the mouse position relative to the window, or the div.

-- labcoat
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

886 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