Bart Gottschalk


I'm trying to determine if there is a way to call the GetRoute() method from script that is embedded in the <body> of the page rather than in the <body onload=...> tag. Here are the two simplest map examples I've been able to construct to illustrate this idea. The second version doens't load in IE but works fine in Firefox. I get the following error in IE -

---------------------------
Error
---------------------------
A Runtime Error has occurred.
Do you wish to Debug

Line: 1
Error: Unexpected call to method or property access.
---------------------------
Yes No
---------------------------

Can anyone help me understand why this is happening in IE and if there is a workaround. I don't control the whole construction (html is built by JSP that is owned by someone else) and the onload tag may prove to be tricky.

Thanks very much!

Bart

Version 1 (Works in IE and Firefox):

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GetRoute Error</title>
<script src="http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>
<script>
function GetMap(){
map = new VEMap("sl_sr_map");
map.LoadMap();
map.GetRoute( '55419', '55403');
};
</script>
</head>
<body onload="GetMap();">
<div id="sl_sr_map"></div>
</body>
</html>

Version 1 (Doesn't Work in IE but is fine in Firefox):

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GetRoute Error</title>
<script src="http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>
<script>
function GetMap(){
map = new VEMap("sl_sr_map");
map.LoadMap();
map.GetRoute( '55419', '55403');
};
</script>
</head>
<body>
<div id="sl_sr_map"></div>
<script language="javascript" type="text/javascript" defer="true">
GetMap();
</script>
</body>
</html>





Re: Calling GetRoute() from script in <body> rather than in <body onload=...>

SoulSolutions


You need to make sure you call your "GetMap()" function after the page has completely loaded.

try this:

http://viavirtualearth.com/Wiki/DeferScript.ashx

if (window.attachEvent) {
window.attachEvent("onload", GetMap);
} else {
window.addEventListener("load", GetMap, false);
}

John.







Re: Calling GetRoute() from script in <body> rather than in <body onload=...>

Bart Gottschalk

John,

Thanks for the suggestion. I've spent some time working with the code you suggested and I'm having some ripple effect issues. Adding the call to GetMap in the <body onload> tag seems to work well and I'm going to try to roll with that.

I'm still interested in understanding why this is an issue in IE but I'm guessing it will just be a black box mystery.

Thanks,

Bart