我尝试使用下面的谷歌RSS阅读器样本来创建一个简单的Chrome扩展,打开凸片在Chrome新闻阅读器扩展
http://code.google.com/chrome/extensions/samples.html#597015d3bcce3da693b02314afd607bec4f55291
我可以添加在弹出的窗口链接,打开的标签页,但不是来自饲料本身。
循环通过在饲料中的项目,抓住标题标签和链接标签,我想标题链接的适当部位
var entries = doc.getElementsByTagName('item');
var count = Math.min(entries.length, maxFeedItems);
for (var i = 0; i < count; i++) {
item = entries.item(i);
// Grab the title for the feed item.
var itemTitle = item.getElementsByTagName('title')[0];
if (itemTitle) {
itemTitle = itemTitle.textContent;
} else {
itemTitle = "Unknown title";
}
// Grab the link for this feed item
var itemLink = item.getElementsByTagName('link')[0];
if (itemLink) {
itemLink = itemLink.textContent;
} else {
itemLink = "Unknown link";
}
var title = document.createElement("a");
title.className = "item_title";
title.innerText = itemTitle; //display title in iframe
title.addEventListener("click", titleLink); // should open link when clicking on title, but does not.
}
// -------------------------------------------------------------------
// Show |url| in a new tab.
function showUrl(url) {
// Only allow http and https URLs.
if (url.indexOf("http:") != 0 && url.indexOf("https:") != 0) {
return;
}
chrome.tabs.create({url: url});
}
function moreStories(event) {
showUrl(moreStoriesUrl);
}
function titleLink(event) {
showUrl(itemLink);
}
为什么这是行不通的任何想法。
如果我替换title.addEventListener(“click”,titleLink); with title.addEventListener(“click”,moreStories);每个标题都会链接到moreStore,我无法获得每个标题链接到itemLink。
感谢