How to get event object in FireFox and IE?
* static event function which worked both IE and FireFox
<body οnmοusemοve="displaycoordNS( event);">
<script>
function displaycoordNS(oEvent){
window.document.title=oEvent.clientX+" : "+oEvent.clientY;
}
</script>
<form>
<div id="div1" >aaaa</div>
</form>
</body>
* dynamic event function which worked both IE and FireFox
<body">
<script>
function Button1_onclick() {
var oH = document.getElementById("div1");
eval("oH.onclick = div1_onclick");
}
function Button2_onclick() {
var oH = document.getElementById("div1");
eval("oH.onclick = null");
}
function div1_onclick(oEvent) {
if (oEvent == undefined)
{ // IE
oEvent = event;
}
alert("div1_onclick2:" + oEvent.type);
}
</script>
<form>
<div id="div1" >aaaa</div>
<div id="div2" ><input id="Button1" type="button" value="enable" οnclick="return Button1_onclick()" /></div>
<div id="div3" ><input id="Button2" type="button" value="disable" οnclick="return Button2_onclick()" /></div>
</form>
</body>
IE: var oEvent = window.event; //or event
in FireFox, it is more complex, you can use different method:
* use callee method.
<body οnmοusemοve=" displaycoordNS();">
<script>
function displaycoordNS(){
var oEvent = arguments.callee.caller.arguments[0];
window.document.title=oEvent.clientX+" : "+oEvent.clientY;
}
</script>
<form>
<div id="div1" >Firefox event object</div>
</form>
</body>
* use apply method
<body οnmοusemοve=" displaycoordNS.apply(this, arguments);">
<script>
function displaycoordNS(){
var oEvent = arguments[0];
window.document.title=oEvent.clientX+" : "+oEvent.clientY;
}
</script>
<form>
<div id="div1" >Firefox event object</div>
</form>
</body>
* static event function which worked both IE and FireFox
<body οnmοusemοve="displaycoordNS( event);">
<script>
function displaycoordNS(oEvent){
window.document.title=oEvent.clientX+" : "+oEvent.clientY;
}
</script>
<form>
<div id="div1" >aaaa</div>
</form>
</body>
* dynamic event function which worked both IE and FireFox
<body">
<script>
function Button1_onclick() {
var oH = document.getElementById("div1");
eval("oH.onclick = div1_onclick");
}
function Button2_onclick() {
var oH = document.getElementById("div1");
eval("oH.onclick = null");
}
function div1_onclick(oEvent) {
if (oEvent == undefined)
{ // IE
oEvent = event;
}
alert("div1_onclick2:" + oEvent.type);
}
</script>
<form>
<div id="div1" >aaaa</div>
<div id="div2" ><input id="Button1" type="button" value="enable" οnclick="return Button1_onclick()" /></div>
<div id="div3" ><input id="Button2" type="button" value="disable" οnclick="return Button2_onclick()" /></div>
</form>
</body>
IE: var oEvent = window.event; //or event
in FireFox, it is more complex, you can use different method:
* use callee method.
<body οnmοusemοve=" displaycoordNS();">
<script>
function displaycoordNS(){
var oEvent = arguments.callee.caller.arguments[0];
window.document.title=oEvent.clientX+" : "+oEvent.clientY;
}
</script>
<form>
<div id="div1" >Firefox event object</div>
</form>
</body>
* use apply method
<body οnmοusemοve=" displaycoordNS.apply(this, arguments);">
<script>
function displaycoordNS(){
var oEvent = arguments[0];
window.document.title=oEvent.clientX+" : "+oEvent.clientY;
}
</script>
<form>
<div id="div1" >Firefox event object</div>
</form>
</body>