Javascript与IE和FF不兼容(调用函数)

时间:2012-11-14 09:56:08

标签: javascript internet-explorer firefox incompatibility

我在javascript中编写了一些代码,我需要它在大多数浏览器上工作,但它只适用于googleChrome,IE和FF不要调用此函数:

<script type="text/javascript">
  showLocation(<?php print "\"$citta2\""?>,<?php print "\"$row[nome] $row[cognome]\""?>,<?php print "\"$row[id]\""?>); return false;
  </script>

(我知道它之所以称之为它是因为它所支持的第一件事就是做出一个转变)你知道为什么那只能在chrome中起作用吗?如果你需要所有文件,我可以在下面发布,但它有点长,我也很肯定问题出在那个电话中。

edit1:这是showLocation代码:

function showLocation(address2,nomi0,id0) {
            alert("1");
    var nomi1 = nomi0;
    var id1 = id0;
    geocoder.getLocations(address1, function (response) {

        if (!response || response.Status.code != 200)
        {
            alert("Errore con il primo indirizzo");
        }
        else
        {
            location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
            geocoder.getLocations(address2, function (response) 
            {
                if (!response || response.Status.code != 200)
                {
                    alert("Errore con il secondo indirizzo");
                }
                else
                {
                    location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                    calculateDistance(nomi1,id1);
                }
            });
        }
    });
}

(它使用谷歌地图api获取城市的经纬度)

1 个答案:

答案 0 :(得分:-1)

不是答案(截至目前)只需要超过评论中允许的600个字符。

首先,让我们让您的脚本标记更容易阅读,并添加一些调试:

<script type="text/javascript">
    try {
        if (window.showLocation)
        {
            showLocation(<?php print "'{$citta2}','{$row[nome]} {$row[cognome]}','{$row[id]}'"; ?>);
        }
        else
        {
            // if you see this message:
            // then you have a syntax error before or within the creation of showLocation
            alert("showLocation has not been created!");
        }
    }
    catch (e) {
        alert("Error from caller: " + e);
    }
</script>



现在在你的其他代码中,添加一些调试:

function showLocation(address2,nomi0,id0) {
    try {
        alert("1");
        var nomi1 = nomi0;
        var id1 = id0;
        geocoder.getLocations(address1, function (response)
        {
            try
            {
                if (!response || response.Status.code != 200)
                {
                    alert("Errore con il primo indirizzo");
                }
                else
                {
                    location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                    geocoder.getLocations(address2, function (response) 
                    {
                        try
                        {
                            if (!response || response.Status.code != 200)
                            {
                                alert("Errore con il secondo indirizzo");
                            }
                            else
                            {
                                location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                                calculateDistance(nomi1,id1);
                            }
                        }
                        catch (e)
                        {
                            alert("Error in callback#2: "+ e);
                        }
                    });
                }
            }
            catch (e)
            {
                alert("Error in callback#1: " + e);
            }
        });
    }
    catch (e)
    {
        alert("Error in functon: " + e);
    }
}


添加更多调试警报_