I was working on a website realign tonight, and finally got around to testing a page in IE that I had implemented a Google Map on. Alas! The page did not load, and gave only an “Operation Aborted” error message. The code I was using worked just fine in Firefox:
if (GBrowserIsCompatible()) {
function createMarker(point,html) {
// FF 1.5 fix
html = ‘
‘;
var marker = new GMarker(point);
GEvent.addListener(marker, “click”, function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
var map = new GMap(document.getElementById(”map”));
var point = new GPoint(-71.473918, 43.330797);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(point, 7);
var marker = createMarker(point,’My Text Here‘)
map.addOverlay(marker);
}
I took some time to do a bit of debugging, and found that when I removed the two divs surrounding my included file, things worked OK. However, that still left me with quite a problem. Thankfully, I was not the first one to have this problem. A quick Google search led me to a page on RyanGrant.net about the Operation Aborted error message. Ryan had run into the same problem, and it was suggested on the Google Maps Google Group to load the map script using an onload event. Unfortunately, this was probably something I should have been doing already in the interest of good coding. Thankfully, a quick fix to my code managed to clear up the problem.
function createMap(){
if (GBrowserIsCompatible()) {
function createMarker(point,html) {
// FF 1.5 fix
html = ‘
‘;
var marker = new GMarker(point);
GEvent.addListener(marker, “click”, function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
var map = new GMap(document.getElementById(”map”));
var point = new GPoint(-71.473918, 43.330797);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(point, 7);
var marker = createMarker(point,’My Text Here‘)
map.addOverlay(marker);
}
}
if(document.getElementById && document.createTextNode) {
window.onload=function(){
createMap();
}
}
Quite frustrating for IE to completely choke on the code as it was, and to provide such an abstract error message. Thankfully, it didn’t require any sort of hack, but only a simple cleaning of the code which improved it in the process anyway. Lesson learned - no more lazy coding!