Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cursor position within  FRAMESET problem

Posted on 2001-08-08
5
Medium Priority
?
233 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 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

688 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