[Web开发] 在网页中动态加入RSS feed 元素
生活随笔
收集整理的這篇文章主要介紹了
[Web开发] 在网页中动态加入RSS feed 元素
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
瀏覽器通過<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。 var head = document.getElementsByTagName("head").item(0);
??????? var link = document.createElement('link'); link.setAttribute('rel', 'alternate');
??????? link.setAttribute('type', 'application/rss+xml');
??????? link.setAttribute('title', feedName);
??????? link.setAttribute('href', feedUrl); head.appendChild(link);
? 原因: 瀏覽器只是在最初頁面導入的時候探測rss feed,即使 解決方案: IE8 中最新的javascript 函數window.external.ContentDiscoveryReset() 可以強制瀏覽器重新探測頁面中的 RSS feed 以及 Web slices, 搜索引擎 Provider 等。
??????? var link = document.createElement('link'); link.setAttribute('rel', 'alternate');
??????? link.setAttribute('type', 'application/rss+xml');
??????? link.setAttribute('title', feedName);
??????? link.setAttribute('href', feedUrl); head.appendChild(link);
? 原因: 瀏覽器只是在最初頁面導入的時候探測rss feed,即使 解決方案: IE8 中最新的javascript 函數window.external.ContentDiscoveryReset() 可以強制瀏覽器重新探測頁面中的 RSS feed 以及 Web slices, 搜索引擎 Provider 等。
總結
以上是生活随笔為你收集整理的[Web开发] 在网页中动态加入RSS feed 元素的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [RHEL5企业级Linux服务攻略]-
- 下一篇: 心如刀割