Solved

cursor position within  FRAMESET problem

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now