In Bing V7 map resets when certain keys are hit...................... RRS feed

  • Question

  • In FireFox 4 and IE9 with Bing V7 when I hit the space bar, enter key or backspace keys the window.onload() orutine is called and the map gets reset.

    This doesn't happen in Bing 6.3 or with IE7 and Bing V7.

    Is there anyway to avoid this from happenning ?


    Steve Kahler
    • Moved by Ricky_Brundritt Friday, March 9, 2012 5:20 PM (From:Bing Maps: Map Control and Web services Development)
    Thursday, April 21, 2011 4:06 PM


  • Thanks this problem is solved by adding the onsubmit="return false;" to the form tag.
    Steve Kahler
    Monday, April 25, 2011 2:25 PM

All replies

  • I can't recreate this - in FF4 under Win7 (64bit) none of these keys seem to do anything. In IE9, space and enter do nothing for me, while backspace causes the browser to go to the previous page...

    Can you post a URL of a map that demonstrates the problem?

    twitter: @alastaira blog: http://alastaira.wordpress.com/
    Thursday, April 21, 2011 4:55 PM
  • Bring up FireFox 4 and go to the web site test.proptools.net.

    Zoom the map in a bit.  Click on the map and then hit the space bar or the enter key.

    You'll see the alert boxes for window load and appsetup appear.   These should not appear.

    Steve Kahler
    Thursday, April 21, 2011 8:01 PM
  • It's got nothing to do with Bing Maps - it's because all of then content in your page is embedded within a <form> element. Hitting enter in IE9/FF4 when a form has focus submits the form, which causes the page to reload, therefore executing your inline script again.

    Get rid of the <form id="form1"> and </form> and try it again - should work fine.

    twitter: @alastaira blog: http://alastaira.wordpress.com/
    Thursday, April 21, 2011 8:48 PM
  • Unfortunately in our main app we use an UpdatePanel control for aspx .Net so we must have the form runat=server in there.

    It does have something to do with Bing 7 becuase our main app has the form tag in there and when running the Bing 6.3 version of it the space bar and enter key do NOT cause a form reset.

    It only happens when running Bing V7.



    Steve Kahler
    Thursday, April 21, 2011 9:04 PM
  • Here's a cutdown version of the code supplied above, in which the map is still placed inside a form element, but based on v6.3:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Bing Push Pin Test</title>
    <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3&mtk=en-us"></script>
    <body ondragstart="return false" oncontextmenu="return false" onselectstart="return false">
      <div id="map" style="position:relative; width:1150px;height:500px"></div>
      <script type="text/javascript">
       alert("got to window load..................");
       var map = null;
       window.onload = appSetup;
       function appSetup() {
        alert("got to appsetup..................");
        map = new VEMap('map');
        map.LoadMap(new VELatLong(51.5, -0.15), 7);


    When I try this in FF4, scroll around and hit the enter key, the page reloads and the "got to xxxx" messages are displayed again, just as it does with v7. As I said before, this is because the enter key is submitting the form and reloading the page. (Admittedly it doesn't happen in IE9 any more. Are you sure that your v6 code works correctly in FF4?)

    If you have to keep the form but don't want it to be submitted then you can override the form submit handler by adding the following:

    <form onsubmit="return false;">


    twitter: @alastaira blog: http://alastaira.wordpress.com/
    Friday, April 22, 2011 7:45 AM
  • Thanks this problem is solved by adding the onsubmit="return false;" to the form tag.
    Steve Kahler
    Monday, April 25, 2011 2:25 PM