To add events

function addEvent( elm, eventName, eventFunct )
{
//DOM Compatible
if ( elm.addEventListener )
{
elm.addEventListener( eventName, eventFunct, false );
return;
}


//IE

if ( elm.attachEvent )
{
elm.attachEvent( 'on' + eventName, eventFunct );
return;
}

//All others use old fashioned way
elm[ 'on' + eventName ] = eventFunct;
return;
}

Get the event target

function getEventTarget( e )
{
if ( e && e.target )
return e.target;
else if ( window.event && window.event.srcElement )
return window.event.srcElement;
else
return null;
}

document.images

The document.images object is not supported by NN2, IE3 and buggy in NN 3.01 and Opera 3.60

window.focus

Flaky support on NN4-Linux, Opera 3 & 4, Opera5-Mac

Browser’s navigator Object ( detection )

Browser detection is not reliable. Although userAgent is available on all browsers, browsers may choose to give incorrect information. Use javascript property/method detection before any object call to make sure the browser supports that object.

//
IE

navigator.appCodeName = Mozilla
navigator.appName = Microsoft Internet Explorer
navigator.appMinorVersion = ;SP2;
navigator.cpuClass = x86
navigator.platform = Win32
navigator.plugins =
navigator.opsProfile =
navigator.userProfile =
navigator.systemLanguage = en-us
navigator.userLanguage = en-us
navigator.appVersion = 4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322; .NET CLR 2.0.50727; InfoPath.2)
navigator.userAgent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322; .NET CLR 2.0.50727; InfoPath.2)
navigator.onLine = true
navigator.cookieEnabled = true
navigator.mimeTypes =



//
Firefox

navigator.userAgent = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4)
Gecko/20060508 Firefox/1.5.0.4
navigator.platform = Win32
navigator.appCodeName = Mozilla
navigator.appName = Netscape
navigator.appVersion = 5.0 (Windows; en-US)
navigator.language = en-US
navigator.mimeTypes = [object MimeTypeArray]
navigator.oscpu = Windows NT 5.1
navigator.vendor =
navigator.vendorSub =
navigator.product = Gecko
navigator.productSub = 20060508
navigator.plugins = [object PluginArray]
navigator.securityPolicy =
navigator.cookieEnabled = true
navigator.onLine = true
navigator.javaEnabled = function javaEnabled() {
[native code]
}
navigator.taintEnabled = function taintEnabled() {
[native code]
}
navigator.preference = function preference() {
[native code]
}

Browser Cookie Handling

// Cookie creation
//
// name: name to store
// value: cookie’s name
// days: expiration in days

function createCookie( name, value, days )
{
if ( days )
{
var date = new Date();
date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}

// Retrieve cookie's value
//
// name: cookie's name
function readCookie( name )
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for ( var i = 0; i

Advertisements