代码之家  ›  专栏  ›  技术社区  ›  Ilian Iliev

Chrome和Safari中的GetElementsByTagname问题

  •  4
  • Ilian Iliev  · 技术社区  · 16 年前

    我正在用javascript分析谷歌地图RSS,并使用以下代码获取点坐标:

    point_coords=items.getElementsByTagname('georss:point')

    不幸的是,它在FF中工作,但在Safari和Chrome中不工作(仍然没有在Opera和IE中测试)

    XML看起来像:

    <item>
        <guid isPermaLink="false">guidNo</guid>
        <pubDate>Mon, 23 Mar 2009 20:16:41 +0000</pubDate>
    
        <title>title text</title>
        <description><![CDATA[text]]></description>
        <author>UniCreditBulbank</author>
        <georss:point>
          42.732342 23.296659
        </georss:point>
      </item>
    
    4 回复  |  直到 9 年前
        1
  •  6
  •   Ilian Iliev    12 年前

    在IE6、7、8、FF、Opera、Chrome和Safari中工作的最终解决方案

    point_coords = item.getElementsByTagName('georss:point')[0];
    if(!point_coords || point_coords == null){
        point_coords = item.getElementsByTagName('point')[0];
    }
    if(!point_coords || point_coords == null){
        point_coords = item.getElementsByTagNameNS('http://www.georss.org/georss', 'point')[0];
    }
    return point_coords
    

    感谢他们提供的所有提示)

        2
  •  3
  •   joran    14 年前

    我也有类似的问题。 getElementsByTagName 在Safari上失败,但在firefox/internet exlporer上失败。结果是firefox/internet explorer需要名称空间前缀,而不是safari,所以现在,根据代理程序…

    getElementsByTagName("iesr:Collection")  // ff/ie
    
    getElementsByTagName("Collection")       // safari
    
        3
  •  1
  •   C. K. Young    16 年前

    从技术上讲, <georss:point> point 不是 georss:point . 试试看。

        4
  •  0
  •   Brandon    9 年前