Javascript Question: location.href in Firefox vs IE

Mar 25, 2008 20:20

Right, this question is for those of you out there who dabble in web development. (The professionals can answer too, if they feel like it)

The pet project combines google maps api and virtual earth api, such that when one drags a marker on the google map, a birdseye view pans to follow it. This works fine. The birdseye view can be in the same page, or in a popup window which holds all 4 birdseye views. No problems. However, I'd like the tool to be usable by government offices, and I think the VE API is off limits to government use without significant fees, and probably not even then for the birdseye views. The same is not true for the birdseye views accessed through map.live.com, directly though the URL(?cp=lat~lon, etc). It will be significantly less smooth, but the base functionality can be provided by simply reloading the birdseye views directly through maps.live.com with new coordinates after every movement of the marker.

So, this is simple. Use window.open to generate a named popup window, then update the location.href everytime the google map marker is moved. This works fine in IE. It breaks in FF. The popup claims to be loading, our favourite little spinning icon spinning away in the top right of FF (2.0.0.12), but nothing ever happens.

Solution.

Everything needs to return false, all the way back down. And then it works. The post I found which hinted at this was based upon activating through a button, and claimed that the button was submitting, and thus needed a return false to stop it, but I'm activating it through javascript only (either via the event on the marker, or in the onclick on a link). So... why do I need to return false?

Functional code snippets:

function LocateVEMap(VELat,VELon) {
  return updateBirdseye(VELat,VELon);  // Structured as a return to return false, to allow FF functionality.
 }

function getBirdseye() {
            if (winBirdseye == null || winBirdseye.closed) {
                    var valLat = document.getElementById("latbox").value;
                    var valLong =  document.getElementById("lonbox").value;
                    var strHref = 'http://maps.live.com/default.aspx?cp=' + valLat + '~' + valLong + '&style=o&lvl=2&v=2'
                    winBirdseye = window.open('about:blank','winBirdseye','location=no,resizable=-1,menubar=no,toolbar=no,scrollbars=yes,width=600,height=600');
                    winBirdseye.location.href = strHref;
                    winBirdseye.focus();
                    winBirdseye.moveTo(800,0);
                    birdseyeVersion = 1;
                    return false;   // Allows FF functionality
                }
         }

function updateBirdseye(aLat, aLng) {
        if (winBirdseye != null && !winBirdseye.closed)  {
            winBirdseye.location.href = "http://maps.live.com/default.aspx?cp=" + aLat + "~" + aLng + "&style=o&lvl=2&v=2"
            winBirdseye.focus();
            return false;    // Allows FF functionality
            }
    }

...
  ...

Open Birdseye Window
Previous post Next post
Up