Sur l’API de Google map, le code proposé ressemble à cela :
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.setUIToDefault();
}
}
Si vous avez de l’AJAX dans vos pages ou que que voulez utiliser le onload du body pour autre chose, cela risque de coincer.
Voici donc l’astuce :
function pageFermeture() {
GUnload();
}
if (window.onload)
{
//Hang on to any existing onload function.
gmapExistingOnload = window.onload;
}
window.onload=function(ev){
//Run any onload that we found.
if (gmapExistingOnload)
{
gmapExistingOnload(ev);
}
if (GBrowserIsCompatible()) {
// custom init (must be specified in the page calling this view)
//gMapsInit();
initialisation_gmap();
}
};
Mise à jour du 10 mars 2010, voici une autre façon de faire :
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function'){
window.onload = func
} else {
window.onload = function() {
oldonload();
func();
}
}
}
addLoadEvent(initialize);
Amusez-vous bien

flux RSS
Twitter
Catégories
Tags: 
