P
petermichaux
Hi,
I have attached an example below that is causing me trouble in Firefox
but not in Safari or Opera. I am trying to create a closure on the
event object in the handleMouseDown function. In Firefox, when the
startDrag function runs, the e object has all the correct properties
but not the correct values.
Any ideas what I have done wrong? If this is a known Firefox bug is
there a standard workaround?
Thanks,
Peter
<html>
<head>
<script type="text/javascript">
function MyObj() {
var thisC = this;
document.getElementById("myDiv").addEventListener("mousedown",
function(e){thisC.handleMouseDown(e);},
false);
};
MyObj.prototype.handleMouseDown = function(e) {
alert(e.pageX + ", " + e.pageY); // for example, outputs 376,
20
var thisC = this;
setTimeout(function() {thisC.startDrag(e);}, 1000);
};
MyObj.prototype.startDrag = function(e) {
alert(e.pageX + ", " + e.pageY); // in Firefox always outputs 0, 0
};
</script>
</head>
<body onload="var myObj = new MyObj();">
<div id="myDiv" style="background-color:lightblue;">
my div
</div>
</body>
</html>
I have attached an example below that is causing me trouble in Firefox
but not in Safari or Opera. I am trying to create a closure on the
event object in the handleMouseDown function. In Firefox, when the
startDrag function runs, the e object has all the correct properties
but not the correct values.
Any ideas what I have done wrong? If this is a known Firefox bug is
there a standard workaround?
Thanks,
Peter
<html>
<head>
<script type="text/javascript">
function MyObj() {
var thisC = this;
document.getElementById("myDiv").addEventListener("mousedown",
function(e){thisC.handleMouseDown(e);},
false);
};
MyObj.prototype.handleMouseDown = function(e) {
alert(e.pageX + ", " + e.pageY); // for example, outputs 376,
20
var thisC = this;
setTimeout(function() {thisC.startDrag(e);}, 1000);
};
MyObj.prototype.startDrag = function(e) {
alert(e.pageX + ", " + e.pageY); // in Firefox always outputs 0, 0
};
</script>
</head>
<body onload="var myObj = new MyObj();">
<div id="myDiv" style="background-color:lightblue;">
my div
</div>
</body>
</html>