It is sometimes not possible to add an event to the body onload, for example within a portal. You can however add the onload and onunload events programatically:
//the map object
var map = null;
//set page event handlers for onload and unload
if (window.attachEvent) {
window.attachEvent("onload", Page_Load);
window.attachEvent("onunload", Page_Unload);
} else {
window.addEventListener("DOMContentLoaded", Page_Load, false);
window.addEventListener("unload", Page_Unload, false);
}
//load map
function Page_Load() {
//add your map loading code here
}
//Clean up all objects
function Page_Unload() {
if (map!=null) {
map.Dispose();
map = null;
}
}