您现在的位置: 365建站网 > 365文章 > [Web开发] 在网页中动态加入RSS feed 元素

[Web开发] 在网页中动态加入RSS feed 元素

文章来源:365jz.com 点击数:352 更新时间:2009-09-18 10:27

浏览器通过<link type="application/rss+xml" ... > 来识别网页中是否存在RSS feed

 <link href="rss.xml" type="application/rss+xml" rel="alternate" title="My Website's RSS Feed" />

Web 开发者常遇到的一个问题是:

有时候需要用Javascript 来动态把这个加入到网页中(见如下代码), 但是发现浏览器无法识别到动态加入的这个Feed。

view plaincopy to clipboardprint?
  1. var head = document.getElementsByTagName("head").item(0);   
  2. var link = document.createElement('link');   
  3.   
  4. link.setAttribute('rel', 'alternate');   
  5. link.setAttribute('type', 'application/rss+xml');   
  6. link.setAttribute('title', feedName);   
  7. link.setAttribute('href', feedUrl);   
  8.   
  9. head.appendChild(link);  

 

原因:

浏览器只是在最初页面导入的时候探测rss feed,即使

解决方案:

IE8 中最新的javascript 函数window.external.ContentDiscoveryReset() 可以强制浏览器重新探测页面中的 RSS feed 以及 Web slices, 搜索引擎 Provider 等。

Tag标签: rss ie rss 种子

生产内容,同时打通搜索引擎(SEO)与AI搜索引擎(GEO)流量入口的软件! 点击进入365建站器 »

您可能感兴趣的文章