2013-10-04 3 views
5

사용자가 내 확장 프로그램 아이콘을 클릭하면 간단한 alert을 표시하고 싶습니다. 이 코드를 시도 :크롬 확장 프로그램에서 알림 대화 상자 표시

{ 
    "manifest_version": 2, 

    "name": "sample", 
    "description": "des", 
    "version": "1.0", 

    "browser_action": { 
    "default_icon": "icon.png" 
    }, 
    "permissions": [ 
    ] 
} 

가 어떻게 표시 할 경고 onClick 이벤트 : chrome.browserAction.onClicked.addListener( alert(1) );, 여기 내 manifest입니까?

+1

시도'의 addListener (함수() {경고 (1) }) ' – georg

+0

@ thg435 작동하지 않았습니다. –

+0

"작동하지 않았습니까?" 펀치를 해보십시오. – georg

답변

6

업데이트 :

이 같은입니다 documention에 따르면 : 여기

chrome.browserAction.onClicked.addListener(function() { 
    alert('Hello, World!'); 
}) 

와는 sample from Google (zip-file)입니다 :

// Copyright (c) 2011 The Chromium Authors. All rights reserved. 
// Use of this source code is governed by a BSD-style license that can be 
// found in the LICENSE file. 

var min = 1; 
var max = 5; 
var current = min; 

function updateIcon() { 
    chrome.browserAction.setIcon({path:"icon" + current + ".png"}); 
    current++; 

    if (current > max) 
    current = min; 
} 

chrome.browserAction.onClicked.addListener(updateIcon); 
updateIcon(); 
+0

작동하지 않습니다. 그 코드가 있어야합니까? –

+0

@MickeyTin 잘 작동합니다! – CodeGroover

+1

샘플을 보내 주셔서 감사합니다.이 줄은 manifest :' "background": { "scripts": [ "myScript.js"]}'에 없습니다. 이제 작동합니다. –

관련 문제