我試圖加載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