2010-02-05 86 views
4

我真的解析谷歌地圖RSS使用JavaScript和使用下面的代碼,以獲得一點問題座標:的getElementsByTagName在Chrome和Safari

point_coords = items.getElementsByTagName( '的GeoRSS:點')

不幸的是,在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> 
+0

感謝您的答案,我想你'重新兩者直接從瀏覽器依賴,所以使用選擇的組合我真的。我仍然無法讓它在任何地方都能正常工作(歌劇還剩),但我希望我能在星期一搞清楚並向你展示解決方案。 再次感謝 – 2010-02-05 22:16:05

回答

6

最終解決方案的工作和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 

感謝所有提示他們做的工作)

1

的Techni cally,<georss:point>的標籤名稱是point,而不是georss:point。試試看。在IE6,7,8,FF,歌劇,鉻

3

類似的問題對我來說。 getElementsByTagName在Safari瀏覽器上失敗,但不是Firefox/Internet Exlporer。根據代理髮現Firefox/Internet Explorer需要命名空間前綴,現在不需要Safari。

getElementsByTagName("iesr:Collection") // ff/ie 

getElementsByTagName("Collection")  // safari