tags:

views:

257

answers:

3

Is it possible to update the URL of an rss <link> tag dynamically, so that when the RSS icon in the location bar is clicked, the browser will direct the user to the updated URL?

For example, using Jquery:

<link id="feed_url" rel="alternate" type="application/rss+xml" title="RSS" href="/feed" />
<script type="text/javascript">
$("#feed_url").attr("href", "/feed?foo=bar");
</script>

The user should now be redirected to /feed?foo=bar rather than /foo.

Note, the values in the query string are determined on the fly on the client-side so the URL must be updated through Javascript. I cannot determine these values on the server side.

+2  A: 

Many browsers will parse the link tag on DocumentComplete and not reparse it later if it changes. So technically it may be updated, but the browser may not notice. You'll have to test in different browsers.

jeffamaphone
A: 

Why would you use javascript to update the URL? Why not just change the HTML?

You're changing the template/view in order to add the JavaScript, so I don't really see any advantage to sending the browser the wrong feed address, and then using JavaScript of all things to correct the address.

If you want to dynamically generate/change the RSS link, that should be done server-side. You could store the feed addresses for different page in the database and insert them into the page dynamically when the page is requested.

e.g.

<link id="feed_url" rel="alternate" type="application/rss+xml"
  title="<? echo $page['RSS']['title'] ?>"
  href="<? echo $page['RSS']['url'] ?>" />
Calvin
The values in the query string are determined on the fly on the client-side. Thus I cannot determine these values on the server side.
lupefiasco
A: 

Remember there are feed readers and agregators which will read the page without javascript. I don't know if it's an issue for you, but if it is, provide a default not-js-modified feed, or disable feeds and add the feed on the fly for the js-clients.

zalew