Defer a script until the page has loaded

This Page is locked
Modified: 2007/05/22 13:33 by ViaVE Visitor
To avoid a dreaded "operation aborted" you must ensure that the page has completly loaded before you run your javascript functions. Typically this is done by using the body onload event as per the VE SDK. If this is not possible use the following:


Just attach to the onload event. Here is code that works in Firefox and IE.
if (window.attachEvent) {
	window.attachEvent("onload", GetMap);
} else {
	window.addEventListener("load", GetMap, false);
}
Simply put this within your js.

Old method
window.onload not the prefered method for attaching to events any more.


function addLoadEvent(func) 
{ 
    var oldonload = window.onload; 
    if (typeof window.onload != 'function') 
        { window.onload = func; } 
    else 
        { window.onload = function() 
            { oldonload(); func(); } 
    }
}



usage:
<script>addLoadEvent(GetMap);</script>