Karthi Shan
Karthi Shan

Reputation: 71

inside div element find out mouse position?

i done one concept of program is find out mouse coordinate position inside div element ... its perfectly working in IE browser only but i cant get answer in mozilla firefox... what is the reason??????????

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Cursor position status display</title>
<script type="text/javascript">

 function getXOffset(e){
if(typeof e.offsetX != 'undefined')
  return e.offsetX;
 else if(typeof e.pageX != 'undefined')
  return e.pageX - e.target.offsetLeft;
}

function getYOffset(e){
 if(typeof e.offsetY != 'undefined')
  return e.offsetY;
   else if(typeof e.pageY != 'undefined')
  return e.pageY - e.target.offsetTop;
}

function displayOffsets(e){
e = (e) ? e : window.event;
window.status = 'x: '+getXOffset(e)+'   y: '+getYOffset(e); 
}

 </script>
 </head>
 <body>
  <div style="width:100px; height:300px;margin:50px 0 0 500px;border:1px solid red;" >
  <div onMouseMove="displayOffsets(event)" style="width:50px; height:300px;     background:#669966;"></div>
  <div >
  </body>
   </html>

Upvotes: 0

Views: 521

Answers (1)

Ayman Safadi
Ayman Safadi

Reputation: 11552

Your function may be working perfectly fine, your problem is probably the window.status part: https://developer.mozilla.org/en/DOM/window.status

This property does not work in default configuration of Firefox and some other browsers: setting window.status has no effect on the text displayed in the status bar.

Maybe try outputing the coordinates into some other element in the page, or better yet, if you have something like Firebug, you can output use the console.

Upvotes: 1

Related Questions