Monday, January 17, 2011

JavaScript Differences between IE and Mozilla - Tutorial 1 on Web Browser Differences

Web Programming on various browsers is a challenging task ( It is relatively easy now with utilities like JQuery) , but for older legacy applicatons - this will give a quick view of what works in IE  and what is the alternative in Mozilla

                             IE                                                                               Mozilla
Get Element by ID Name
document.all
document.getElementById

Get All Elements on a Page
use the document.all array
document.getElementById('*')

Get all child elements from a node
element.children works in IE to get all HTML 
elements. element.childNodes works in all
 browsers but returns all nodes, 
not just HTML elements.


Make one node the child of another
applyElement (appendChild works too)
appendChild

Create an XMLHttp Object
new ActiveXObject(ObjID);
ObjID can be one of ['Msxml2.XMLHTTP.6.0', 
'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', '
Microsoft.XMLHTTP'], 
depending on what the client has installed
new XMLHttpRequest();

Set or read the text value of an element
innerText
textContent

Read/Set the float property of an element
style.cssFloat
style.styleFloat

Get the event object in a function
window.event
must be passed to the function

Get the target of an event
event.srcElement
event.target

Get the mouse position on screen
event.clientX+object.scrollLeft-object.clientLeft
and
event.clientY+object.scrollTop-object.clientTop
(phew!)
event.pageX and event.pageY

Get window size
document.body.clientHeight or document.documentElement.clientHeight, 
depending on the doctype
window.innerHeight and window.innerWidth

One way to set position/size of an element
pixelLeft, pixelTop, pixelHeight and pixelWidth
left, top, height and width

No comments:

Post a Comment

subversion video