Wednesday, July 2, 2008

Event Objects In Javascript

Src Element
In Explorer =
The element which fired the event.
In FireFox = target, but in Firefox the nodes of type text can also fire events,
so to keep things working you'll need to climb up the tree until you find a element's (tag's) node:
var node = e.target;
while(node.nodeType != node.ELEMENT_NODE)
node = node.parentNode;


To get the Position of the window browser
relative to the screen.
In Explorer =
window.screenLeft
window.screenTop
In FireFox =
window.screenX - someValue,
window.screenY + someValue
These properties are not extactly the same as the Explorer.
In explorer they give the coordinates of the origin of
the IE control, while in Firefox they give the origin
of the Firefox window itself.

Function to element's event_name.
In Explorer = element.attachEvent( event_name, function)
In FireFox =
element.addEventListener(event_name, function, false)

Function to the node element
In Explorer =contains(node)
In FireFox =
DOM level 2 does not have an equivalent method,
but a very simple method like the shown below can be used
(it works in Firefox and Explorer):
function contains(a, b)
{
// we climb through b parents
// till we find a
while(b && (a!=b) && (b!=null))
b = b.parentNode;
return a == b;
}
The new DOM level 3 standard defines
node.compareDocumentPosition() and
Firefox already implements it, but Explorer doesn't.

To obtain the window in which the document is.

In Explorer =document.parentWindow
In FireFox = document.defaultView.
Note that the window object is available everywhere.

Access a form
In Explorer = myForm
In FireFox =document.myForm, it works everywhere.



No comments: