In most browsers, when an event handler is triggered, an instance of the class named Event is passed into the handler as the first parameter. However, Internet Explorer, which has always been in the mainstream, behaves in its own way and saves the Event instance in a global attribute called event.
if (!event) event=window.event;
The above statement is used to detect whether the event parameter is undefined or null. If so, assign the event attribute of the window to it, thereby eliminating browser differences.
To obtain a reference to the target element, use the target attribute in standards-compliant browsers and the srcElement attribute in IE to handle this inconsistency through object detection
var target=(event.target) ? event.target : event.srcElement;
This statement checks whether the definition of event.target exists. If it exists, assign its value to the local variable target; otherwise, assign event.srcElement to target.