how to get src element in javascript for firefox
I am try to catch form event in javascript
var event = window.event.srcElement;
This is working fine in IE, but in Netscape/Firefox where eve开发者_如何学Cnt return undefined.
Can someone tel me how to catch event in Netscape/Firefox?
IE and Netscape play different games. But you can easily make it crossbrowser as such:
if (window.event) e = window.event;
var srcEl = e.srcElement? e.srcElement : e.target;
Use .target
:
var event = event.target;
Or to check for both/fallback in a single statement:
function myHandler(event) {
var target = window.event.srcElement || event.target;
}
(In both cases... I'd rename your variable, since this isn't the actual event
object, but an element.)
精彩评论