Solved

cursor position within  FRAMESET problem

Posted on 2001-08-08
5
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

627 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