0
확장 프로그램 아이콘을 클릭하면 사용자에게 버튼이 표시되고 해당 버튼을 클릭하면 전달 된 매개 변수가 표시되는 Chrome 확장 프로그램이 생성됩니다. 원본 페이지에서. 이상하게도, 디버그 (즉, 확장 아이콘을 오른쪽 클릭하고 "Inspect popup"을 클릭)하면 디버깅을하지 않으면 버튼을 클릭하면 빈 페이지가 표시됩니다.Chrome 확장 - javascript onClick 기능은 디버깅시에만 작동합니다.
manifest.json을
{
"name": "test name",
"version" : "0.1",
"description": "test description",
"browser_action":
{
"default_icon": "icon_128.png",
"popup": "test.html"
},
"permissions": [
"tabs", "http://*/*", "https://*/*"
]
}
test.html를
<HTML>
<BODY>
<script type="text/javascript">
var currentWindowID = -1;
window.onload = function(e){
chrome.windows.getCurrent(function(w)
{
currentWindowID = w.id;
});
}
function openNextPage(){
console.log("in openNextPage");
chrome.tabs.create(
{url: "test2.html"},
function(tab)
{
chrome.tabs.sendRequest(tab.id, {someParam: currentWindowID});
}
);
console.log("exiting openNextPage");
}
</script>
<input type="button" value="Show next page" onClick="openNextPage()">
</BODY>
</HTML>
test2.html
<HTML>
<script type="text/javascript">
chrome.extension.onRequest.addListener(function(request)
{
document.write("<h1>test</h1>");
document.write("<h2>value=" + request.someParam + "</h2>");
});
</script>
</HTML>
예,이 작품
background.html! 고맙습니다. 다른 사람을위한 참고 사항 :이 라인을 manifest.json 파일에 추가해야합니다. \t "background_page": "background.html", – Anssssss