VEMap.DetachEvent Method

You are not viewing the latest version of the AJAX control. Bing Maps AJAX V7 is the recommended JavaScript control for Bing Maps. If you need this documentation, it is available in as a CHM or PDF download.

Detaches the specified map control event so that it no longer calls the specified function.

VEMap.DetachEvent(event, function);


Parameter Description


The name of the map control event that generates the call.


The function that was specified to run when the event fired.

For a list of map control events, see VEMap Events.

Because a single event can be attached to multiple functions, you must specify the event and function names when detaching.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <script type="text/javascript" src=""></script>

      <script type="text/javascript">
         var map = null;
         var shape = null;
         // Latitude and longitude values for the approximate center of Boston, MA
         var lat = 42.3595586931348;
         var lon = -71.06094360351562;
         // Point values to draw an octagon shape
         var points=[new VELatLong(lat,lon-0.15),
            new VELatLong(lat+0.1,lon-0.05),
            new VELatLong(lat+0.1,lon+0.05),
            new VELatLong(lat,lon+0.15),
            new VELatLong(lat-0.1,lon+0.05),
            new VELatLong(lat-0.1,lon-0.05)];
         // Custom HTML for pushpin popup (This is NEW in V5!)
         var description = 
            "<div>" +
            "<h4>This is the center of Boston, MA</h4>" +
            "<p>Latitude = 42.3595586931348.</p>" +
            "<p>Longitude = -71.06094360351562.</p>" +
         function GetMap()
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(lat,lon));

            document.getElementById('banner').innerHTML = document.title;
         function drawPolygon()
               var shape = new VEShape(VEShapeType.Polygon,points);
               shape.SetTitle("<div id='customTitle'><h3>Custom Title</h3></div>");
               document.getElementById('label').innerHTML = 
                  "<p>Hover over the polygon for info about this shape!</p>"
               // The onmouseover event which calls the shapeInfo function
               map.AttachEvent("onmouseover", shapeInfo);
               // The onmouseout event that calls the shapeInfo function to clear the info element
               map.AttachEvent("onmouseout", shapeInfo);
               // The onclick event to call the callPopUp function
               map.AttachEvent("onclick", callPopUp);
            // This example features handling exceptions with the VEException object
               document.getElementById('label').innerText =
                  VEException.message +
                  " : " +
                  " : " +
         function detach()
            // Detach all events
            map.DetachEvent("onmouseover", shapeInfo);
            map.DetachEvent("onmouseout", shapeInfo);
            map.DetachEvent("onclick", callPopUp);
         function shapeInfo(e)
            if(e.elementID != null)
               document.getElementById("label").innerText = 
                  "Event: " + 
                  e.eventName + 
                  "; Shape ID:  " +
                  e.elementID + 
                  "\n\nClick on the polygon for additional information.";
               document.getElementById("label").innerText = "";
         function callPopUp(e)
            if(e.elementID != null)
                  "You can now call other functions via events \n" + 
                  "This event was " +
               return false;
   <body onload="GetMap();">
      <div id="banner" style="background-color: #CCCCFF; border: thin blue dashed; border-bottom: 0px;
         font-family: Helvetica, sans-serif; font-style: italic; font-size: medium; width: 400px">
      <div id="myMap" style="position: relative; width: 400px; height: 400px; border: thin blue groove">
      <div id="buttons" style="position: static; left: 11px; top: 401px">
         <input name="Button1" type="button" 
            value="Click to Draw Shape and Attach Events" onclick="drawPolygon();" />
         <input name="Button2" type="button" value="Click to Detach Events" onclick="detach();" />
         <div id="label" style="position: relative; left: 0px; top: 0px; width: 399px;">
            <label id="Label1">