PDA

View Full Version : Changing the RSS link in the head of a document. Firefox bug?


FiZiX
01-23-2008, 09:55 PM
Hi all. I hope you can help me with this one:

I'm trying to change the RSS link in the head of my page dynamically. This is the function I made to do it:

function updateRSSLinks(title, link) {
rssmetalink = document.getElementById('rssmetalink');
dochead = document.getElementsByTagName('head')[0];
dochead.removeChild(rssmetalink);
rssmetalink.title = title;
rssmetalink.href = link;
dochead.appendChild(rssmetalink);
}

And here's a test document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test</title>
<link rel="alternate" id="rssmetalink" type="application/rss+xml" title="Old Title" href="http://www.oldlink.com/feed.xml">
<script type="text/javascript">
function updateRSSLinks(title, link) {
rssmetalink = document.getElementById('rssmetalink');
dochead = document.getElementsByTagName('head')[0];
dochead.removeChild(rssmetalink);
rssmetalink.title = title;
rssmetalink.href = link;
dochead.appendChild(rssmetalink);
}
</script>
</head>
<body>
<input type="button" onclick="updateRSSLinks('New Title', 'http://www.newlink.com/feed.xml');" value="Test">
</body>
</html>

The code works in that it doesn't give an error and the new link appears in the head. However, at least in Firefox, the old link never gets deleted so I wind up with another link every time I run the code. Firebug only shows one link in the DOM.

I originally tried editing the link in place but Firefox never reflected the changes even though Firebug showed it was changed. That's why I have the code to remove and append it after the changes are made.

Let me know if you have any ideas for how to work around this bug.

Thanks!

skyrider01
01-23-2008, 11:41 PM
You mean that you see duplicate entries when you check in the firefox address bar? after you have run the code a few times.

I have not come across anything that controls that from javascript etc, but depending on your needs you could set it with a cookie maybe and then refresh the page, that way firefox should get it right, I have not tried that though.

FiZiX
01-24-2008, 04:34 PM
You mean that you see duplicate entries when you check in the firefox address bar? after you have run the code a few times.

Correct.

I have not come across anything that controls that from javascript etc, but depending on your needs you could set it with a cookie maybe and then refresh the page, that way firefox should get it right, I have not tried that though.

I wanted to be able to change it without refreshing since all the content on my page is dynamically loaded.