ajaxコールを実行した後のchrome拡張機能では、id #leadと#detailを持つdivの段落内を検索する必要があります。 cssクラスを追加するテキストが見つかった場合。クロムエクステンションを実行していないdiv内の検索jquery code
私のコードは次のようになります。
function retrieveBlicCheckedFacts(tabUrl){
var data = {currentUrl: tabUrl};
$.support.cors = true;
$.ajax({
type: "POST",
url: API_URL_FIND,
crossDomain: true,
data: JSON.stringify(data),
contentType: "application/json",
success: function(respData){
console.log(respData); //here data are printed correctly
$("#lead, #detail").find('p').each(function() {
for (var count = 0; count < respData.length; count++) {
var findCheckedFact = respData[count]["text"];
var str = $(this).text();
console.log(str);
if (str.indexOf(findCheckedFact) >= 0) {
$(this).html(
$(this).html().replace(findCheckedFact, "<span class='red'> $& </span>")
);
}
}
});
},
error: function(err){
console.log(JSON.stringify(err));
}
});
}
respDataは、このようなリストである:
[{"text":"test" , "type":"example" ,"_id": {"$oid": "570e686951d720724aa06fe7"}} ,{"text":"test" , "type":"example", "_id": {"$oid": "570e686951d720724aa06fe8"}} ]
が、私はそれはそれは段落に来るときを除いて、すべてが良い行くデバッグ、それはそれの中に入っていない、理由は何ですか?マニフェストjsで、私はすでに選択したURLに変更を加えたいパーミッションを追加します。 助けてください
編集: 上記のコードはchecker.js
です。 私のマニフェストのコードはです。http://*www.mydomain.rs/
は、私がこれらの変更を加えたい私の希望するドメインです。
"background": {
"persistent": false,
"scripts": [
"js/jquery-1.12.0.min.js",
"background.js",
"checker.js"
],
"css": ["custom-css.css"]
},
"permissions": [
"notifications",
"contextMenus",
"storage",
"tabs",
"http://*www.mydomain.rs/"
],
Webページのコードのようなものになります。あなたのAJAX呼び出しが背景ページにある、彼らは別のに住んでいるので、それが直接、現在のページのDOMにアクセスすることはできません
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="trunk">
<div id="main">
<div id="lead"> Lorem Ipsum is simply dummy text </div>
<div id="detail" class="detail intext" itemprop="articleBody">
<p> What is Lorem Ipsum</p>
<p> Why do we use it?</p>
<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text. </p>
</div>
</div>
</div>
</body>
</html>
上記のコードはどこに貼り付けましたか?コンテンツスクリプトまたは背景ページ? '#lead'はどこですか?現在のWebページまたはポップアップページ?あなたの 'マニフェストのように詳細を提供してください。json' –
あなたのajaxコールはどこですか?あなたはバックグラウンドページに入れましたか?そうであれば、バックグラウンドページと現在のウェブページは異なるコンテキストで生きているので、 '#lead'を得ることはできません。コミュニケーションのためにメッセージを渡す必要があります。 –
@HaibaraAi私は自分の質問を編集しました。鉛と詳細のdivは、ブラウザに読み込まれたページの中にあります。私はまた、私のマニフェストからいくつかのコードを追加します。 –