Solved

cursor position within  FRAMESET problem

Posted on 2001-08-08
5
207 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 50 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

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