2011-08-05 42 views
0

查找和使用的机构AccuWeather花粉计数谷歌的应用程序,但它抛出一个错误的IE浏览器。JavaScript错误在IE(的getElementsByTagName(...)项(...)”为空或不是一个对象)

这里是一个直接脚本的链接:

http://www-igprev-opensocial.googleusercontent.com/gadgets/ifr?exp_rpc_js=1&exp_track_js=1&url=http%3A%2F%2Fwhapowllc.googlepages.com%2Fpollen.xml&container=igprev&view=default&lang=en&country=US&sanitize=0&v=45408d622dfd6df4&parent=http://www.google.com&libs=core:core.io:core.iglegacy:auth-refresh&is_signedin=1&synd=igprev&view=default

这里是有问题的环绕脚本:

 function setContent(url) { 
     _IG_FetchXmlContent(url, function (response) { 
      if (!response) { 
       msg.createDismissibleMessage("Error loading location data. Please try again later."); 
       echoDefault(); 
      } else if (response.firstChild.nodeName != 'error' && 
       parseInt(response.getElementsByTagName('citylist').item(0).getAttribute('us')) 
       + parseInt(response.getElementsByTagName('citylist').item(0).getAttribute('intl')) 
       + parseInt(response.getElementsByTagName('citylist').item(0).getAttribute('extra_cities'))) { 
       mylocation = response.getElementsByTagName('location').item(0).getAttribute('location'); 
       url = 'http://whapw.accu-weather.com/widget/whapw/weather-data.asp?location=' + mylocation; 

       _IG_FetchXmlContent(url, function (response) { 
        if (!response) { 
         msg.createDismissibleMessage("Error loading pollen data. Please try again later."); 
         echoDefault(); 
        } else { 
         var tree = response.getElementsByTagName('tree').item(0).firstChild.nodeValue; 
         var weed = response.getElementsByTagName('weed').item(0).firstChild.nodeValue; 
         var grass = response.getElementsByTagName('grass').item(0).firstChild.nodeValue; 
         var mold = response.getElementsByTagName('mold').item(0).firstChild.nodeValue; 
         var airquality = response.getElementsByTagName('airquality').item(0).firstChild.nodeValue; 
         var airqualitytype = response.getElementsByTagName('airqualitytype').item(0).firstChild.nodeValue; 
         var airqualitystyle = ''; 

错误是从该行报告:

} else if (response.firstChild.nodeName != 'error' && 

工作正常FF /铬,但在IE中我得到:

网页错误的详细信息

用户代理:Mozilla的/ 4.0(兼容; MSIE 8.0; Windows NT 6.1;三叉戟/ 4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; 3M/MSIE 8.0) 时间戳:周五,2011年8月5日8时01分57秒UTC

Message: 'getElementsByTagName(...).item(...)' is null or not an object 
Line: 986 
Char: 12 
Code: 0 
URI: http://www-igprev-opensocial.googleusercontent.com/gadgets/ifr?exp_rpc_js=1&exp_track_js=1&url=http%3A%2F%2Fwhapowllc.googlepages.com%2Fpollen.xml&container=igprev&view=default&lang=en&country=US&sanitize=0&v=45408d622dfd6df4&parent=http://www.google.com&libs=core:core.io:core.iglegacy:auth-refresh&is_signedin=1&synd=igprev&view=default 

任何想法是什么造成这个错误?

在此先感谢。

+2

请添加代码的相关部分。 –

+0

该脚本位于我发布的顶部链接(我对JS很陌生,所以不知道代码的“相关”部分真的会是什么)。 –

+0

任何人都不应该为了帮助你而遵循链接(如果链接将来无法访问,那么该问题就变得毫无意义)。相关部分将会是引发错误的行和周围的代码。这行代码依赖于任何东西。 –

回答

1

在某些版本的IE中存在一些奇怪的地方,item(0)返回NodeList的长度,而不是第一个项目。相反,只需使用索引访问项目:

...getElementsByTagName('...')[0]; 
+0

谢谢,我已经更换的部件(0)'s的[0],但是我现在似乎越来越‘错误加载位置数据,请重试’。 您可以点击此处查看:http://bit.ly/pSeSuC 在IE浏览器现在的工作虽然。 –

+0

对不起,完整的缩小脚本。如果你想让我调试你可能不喜欢我的速度。 :-) – RobG

+0

恐怕这不是我的剧本Rob,这是我从Accuweather中拿走Google小工具的一个!我对Javascript毫无头绪,因此无法发表评论,但我会为此付诸表决。只是真的想让它在IE中工作。 –

相关问题