mscir wrote:
[color=blue]
> DU wrote:
> <snip>
>
> I tried your code, it looks a lot cleaner than the approach I posted,
> and it works great in my (Win98 SE) IE6, but not in my Netscape 7.1 or
> Firefox 0.8.[/color]
innerText is not a W3C DOM 2 attribute nor a DOM 2 CharacterData
attribute. nodeValue though is and it is supported by MSIE 6!
Here's what I did:[color=blue]
>
> function init(){
> if(document.addEventListener) {
> document.getElementById("idImageToMonitor").addEve ntListener("mousemove",
> TrackCoordinatesInImage, false);
> } else if(window.event && document.getElementById) {
> document.getElementById("idImageToMonitor").onmous emove =
> TrackCoordinatesInImage;
> }
> }
>
> function TrackCoordinatesInImage(evt){
> var Coordinate_X_InImage;
> var Coordinate_Y_InImage;
> Coordinate_X_InImage = Coordinate_Y_InImage = 0;
> if(window.event && !window.opera && typeof event.offsetX == "number") {
> // IE 5+
> var Coordinate_X_InImage = event.offsetX;
> var Coordinate_Y_InImage = event.offsetY;
> } else if(document.addEventListener && evt && typeof evt.pageX ==
> "number"){
> // Mozilla-based browsers
> var Element = evt.target;
> var CalculatedTotalOffsetLeft, CalculatedTotalOffsetTop;
> CalculatedTotalOffsetLeft = CalculatedTotalOffsetTop = 0;
> while (Element.offsetParent) {
> CalculatedTotalOffsetLeft += Element.offsetLeft ;
> CalculatedTotalOffsetTop += Element.offsetTop ;
> Element = Element.offsetParent ;
> }
> Coordinate_X_InImage = evt.pageX - CalculatedTotalOffsetLeft ;
> Coordinate_Y_InImage = evt.pageY - CalculatedTotalOffsetTop ;
> }
> document.getElementById('div1').innerText = "X:
> "+Coordinate_X_InImage+" Y: "+Coordinate_Y_InImage;[/color]
Change that above line to this:
if(document.getElementById('div1').childNodes[0] &&
document.getElementById('div1').childNodes[0].nodeType == 3)
{
document.getElementById('div1').childNodes[0].nodeValue = "X:
" + Coordinate_X_InImage + " Y: " + Coordinate_Y_InImage;
}
and make sure that div1 is without blank spaces (or is truly the first
text node), like this:
<div id="div1"> </div>
and this should work without a problem on all W3C DOM 2 CharacterData
conforming agent (that includes MSIE 6).
Demos:
Performance comparison between innerHTML attribute and DOM's nodeValue
when modifying the text data of a node of type TEXT_NODE
http://www10.brinkster.com/doctorunc...NodeValue.html
Interactive DOM level 2 CharacterData Interface attributes and methods
tests:
http://www10.brinkster.com/doctorunc...acterData.html
[color=blue]
> }
>[color=green]
>> I have pages which uses+explains this code, also for Opera 6.x and
>> Opera 7.x.
>> DU[/color]
>
>
> Would you post the URL with code explanations so I can read up on this?
>
> Thanks,
> Mike
>[/color]
Here's a few:
(use MSIE 6 for this link)
http://www10.brinkster.com/doctorunc...dowsMSIE6.html
(use a Mozilla-based browser for this link)
http://www10.brinkster.com/doctorunc...nerWidthHeight
In the code of that page, I commented the part like this in function
MovesInNS6(evt)
/*
var elem = evt.target ;
var CalculatedTotalOffsetLeft = CalculatedTotalOffsetTop = 0;
while (elem.offsetParent)
{
CalculatedTotalOffsetLeft += elem.offsetLeft;
CalculatedTotalOffsetTop += elem.offsetTop;
elem = elem.offsetParent;
}
*/
and I explained it around the area of the anchor #windowInnerWidthHeight
(use Opera 7 for this link)
http://www10.brinkster.com/doctorunc...WindowsO7.html
(use Opera 6 for this link)
http://www10.brinkster.com/doctorunc...WindowsO6.html
(use Opera 7 for this link)
http://www10.brinkster.com/doctorunc...pera7Bugs.html
and go+click item #11- event.offsetX and event.offsetY coordinate
values... for the demo:
http://www10.brinkster.com/doctorunc...gOffsetXY.html
DU