Get Rss feed location from current website

Discussion in 'JavaScript' started by CosmosCR, Jun 15, 2006.

  1. #1
    For example, to get the URL or title you do this:
    var URL = unescape(location.href)
    var Title = unescape(document.title)

    How can i get the RSS feed location?

    I assume i have to find this, and get it from that.
    <link rel="alternate" type="application/rss+xml" title="RSS - Title" href="feeds/rss.xml" />
     
    CosmosCR, Jun 15, 2006 IP
  2. DXL

    DXL Peon

    Messages:
    380
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    function locateFeed() {
        var els = document.getElementsByTagName('link');
        for(i=0;i<els.length;i++) {
            if(els[i].getAttribute('title').indexOf('RSS') > -1) {
                var feed = els[i].getAttribute('href');
            }
        }
        return feed;
    }
    Code (markup):
    This script assumes that RSS is in the title attribute, I believe this is the best way to catch the right link element.

    This one checks if the rel="alternate":
    function locateFeed() {
        var els = document.getElementsByTagName('link');
        for(i=0;i<els.length;i++) {
            if(els[i].getAttribute('rel') == 'alternate') {
                var feed = els[i].getAttribute('href');
            }
        }
        return feed;
    }
    Code (markup):
     
    DXL, Jun 16, 2006 IP