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!
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!