我试图加载URL然后检查锚的特定文字,现在我想要设置anchar tag.How我能做到这一点的点击的事件到目前为止,我的代码:?如何加载网址并检查点击链接的事件?
$.get(y, function(data) {
console.log(data);
$(data).find('a').each(function() {
console.log($(this).text());
if($(this).text().indexOf("Full Text as PDF")>=0)
{
alert($(this).text());}
});
PS:我正试图在Chrome扩展中做到这一点。 更新的代码:
chrome.tabs.onActivated.addListener(function(activeInfo){
chrome.tabs.get(activeInfo.tabId, function(tab){
y = tab.url;
$.get(y, function(data) {
console.log(data);
$(data).find('a').each(function() {
console.log($(this).text());
if($(this).text().indexOf("Full Text as PDF")>=0)
{ alert($(this).text());
$(this).on("click", function()
{ console.log("link clicked");
alert("link clicked");
});
}
});
});
});
});
恐怕你的问题缺乏了解极少。您试图获取已打开页面的副本,将该事件复制到您的$ .get'中,然后以某种方式期望该处理程序在原始tab_中工作。 – Xan
这是[XY问题](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)你在这里。请阅读Chrome扩展[体系结构概述](https://developer.chrome.com/extensions/overview#arch)和[内容脚本文档](https://developer.chrome.com/extensions/content_scripts)以了解朝对的方向发展。 – Xan
这就是我真正想要的! [链接]:(http://stackoverflow.com/questions/24857334/how-to-get-the-url-of-previous-page-in-chrome-extension)..我无法做到这一点所以我想这样做! – user3668325