Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

javascript - getElementsByTagName problem in chrome and safari

I`m parsing a Google Maps RSS with javascript and using the following code to get the point coordinates:

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

Unfortunately it works in FF but not in safari and chrome (still not tested in Opera and IE)

The XML looks like:

<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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Final solution working in IE6,7,8, FF, Opera, Chrome and 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

Thanks for all hints they did the job )


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...