순수한 자바 스크립트로 Chrome 확장 프로그램을 작성하여 노드 모음을 가져 와서 일부 변경했습니다.Chrome 확장 자바 스크립트가 제대로 작동하지 않음
var list = document.getElementsByClassName("testclass");
console.log(list); //1
console.log(list.length); //2
console.log(list[0]); //3
이의 출력으로 온다 : 그래서, 진형
1. HTMLCollection object with all elements and length: <no of elements> and __proto__: HTMLCollection
2. <no of elements>
3. First Element
: 나는
jsfiddle에서 제공
1. An object [item:function, namedItem:function], which has all the elements and a length: <number of elements> and __proto___: HTMLCollection (As Expected)
2. 0
3. undefined
같은 일이, 내가 적절한 출력을 얻을
사용되는 자바 스크립트가 동일 할 때 왜 반복 할 수 없습니까? Chrome 확장 프로그램을 사용할 때해야 할 일이 있습니까? '
Heres는 내 manifest.json을 할 경우에 도움이 :
{
"manifest_version": 2,
"name": "Something",
"description": "Something something...",
"version": "1.0",
"permissions": [
"tabs",
"notifications",
"http://*/",
"https://*/"
],
"content_scripts": [{
"matches": ["https://*","http://*"],
"js": ["testscript.js"],
"run_at": "document_end"
}],
"web_accessible_resources": ["samplejs.js"],
"browser_action": {
"default_popup": "popup.html"
}
}
내 자바 스크립트 코드는 testscript.js
어디에서 컬렉션을 가져 오려고합니까? –
궁극적으로 모든 페이지의 DOM 내용을 수정하기 위해 content_scripts와 함께 크롬 확장을 작성합니다. –
위의 코드는'testscript.js'의 코드입니다. –