JavaScript
x
4
1
var x = event.target||event.srcElement;
2
document.getElementById(x.id).style.left = 200 + "px" ;
3
document.getElementById(x.id).style.top = 100 + "px" ;
4
Works fine on Google Chrome and IE but not on Firefox. Tried it on Google. Google says event.srcElement
(works on IE but not on Firefox) so I have added event.target
but still not working. Is there anymore changes I need to do to work on Firefox? By the way I’m using 3.5 version of Firefox.
JavaScript
1
9
1
function up()
2
{
3
dragok = false;
4
document.onmousemove = null;
5
var x = event.target||event.srcElement;
6
document.getElementById(x.id).style.left= 200 + "px" ;
7
document.getElementById(x.id).style.top= 100 + "px" ;
8
}
9
Please help me to make it work on Firefox
Advertisement
Answer
Make sure you define event
as a formal parameter to the handler.
IE
defines it globally, and Chrome
defines it both in both places, so it works either way, but Firefox
only defines it as a function parameter.
JavaScript
1
11
11
1
function up( e ) {
2
// ^-----------------------------------------------------+
3
if( !e ) e = window.event; // <---needed this --- and this ->--+
4
5
dragok = false;
6
document.onmousemove = null;
7
var x = e.target||e.srcElement; // <--- and these
8
document.getElementById(x.id).style.left= 200 + "px" ;
9
document.getElementById(x.id).style.top= 100 + "px" ;
10
}
11