[JavaScript]Event Object in FireFox and IE
2007-05-14 17:53
429 查看
How to get event object in FireFox and IE?
* static event function which worked both IE and FireFox
<body onmousemove="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" onclick="return Button1_onclick()" /></div>
<div id="div3" ><input id="Button2" type="button" value="disable" onclick="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 onmousemove="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 onmousemove="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 onmousemove="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" onclick="return Button1_onclick()" /></div>
<div id="div3" ><input id="Button2" type="button" value="disable" onclick="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 onmousemove="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 onmousemove="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>
相关文章推荐
- javascript window.event.clientX in Firefox and cursor:pointer
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Professional JS(13.3.1Event Object in DOM/IE/Cross-Browser/UI&Focus&Mouse and Wheel event[half])
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- JavaScript Var 'Undefined' in Firefox; IE and Opera Work fine
- User javascript to catch ctrl in IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- 大量Firefox和IE不兼容的javascript代码: runtimeStyle, event.srcElement
- Object-Oriented Event Listening through Partial Application in JavaScript
- Defined XmlHttp Object for both IE and FireFox
- Print all attributes and values in a Javascript Object
- Javascript的for...in语句在IE和Firefox的差异
- HTTPAuth Logout in Chrome, Firefox and IE with jQuery
- custom event in javascript and jquery
- Difference between event.target and event.currentTarget properties in an event object.
- how to focus to a div both in firefox and IE
- IE and Firefox compatible javascript to reference innerText/text attribute
- Object-orientation and inheritance in JavaScript: a comprehensive explanation