コンソールでは、document.getElementById( '...')を入力して値を取得できます。または.textContentさえ、私が望む文字列を取得します。Chrome拡張機能 - Document.getelementbyId(...)がnullに評価されていますか?
これを私のクロムエクステンションにポップアップして実行すると、document.getElementById( '...')をnullとして評価します。どうしたの?
manifest.jsonを:
{
"name": "CSUF RMP",
"version": "0.1",
"manifest_version" : 2,
"description": "Displays professor ratings on icon click",
"background" : {
"scripts" : ["background.js"]
},
"browser_action": {
"default_icon": "icon16.png"
},
"content_scripts": [
{
"matches": ["https://mycsuf.fullerton.edu/*"],
"js": ["script.js"]
}
],
"permissions": ["<all_urls>", "*://*/*", "http://*/*", "https://*/*"]
}
Background.js:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {file: "script.js"});
});
私script.jsは私が一番上に掲載するもの文字通りです。スクリプトはウェブページのDOMにアクセスする必要があるため(コンテンツスクリプトが必要です)、アイコン(したがって、background.js)をクリックして実行します。
私はページを実行してアラートを表示できますその行はページのDOMを評価していません。ただnullです。
'document.getElementById( '...')' - 本当ですか?私はIDが値として "..."を持つことができないと思った –