2012-05-06 2 views
0

onClick 함수에서 chrome.contextMenus.create title 속성에 대한 참조를 얻고 싶습니다. 예를 들어TITLE에 대한 참조를 얻는 방법, chrome.contextMenus.create onClick 함수에서?

는 :

chrome.contextMenus.create({"title": "sometitle", "contexts":["selection"], "onclick": searchSelection}); 

function searchSelection(info, tab){ 
    var query = "<i want title (sometitle) here>"+info.selectionText; 
    var url = "http://www.google.com/search?q="+query; 
    chrome.tabs.create({url: url}); 
} 

나는 검색,하지만이 일을 아무 옵션을 찾을 수 없습니다.


+1 질문 : contextMenu 항목을 인라인 편집 할 수있는 방법이 있습니까? 또는 CM 요소 다음에 편집 가능한 입력 필드를 추가 하시겠습니까? 아니,하지만 질문에 대한 가치가 있다고 생각해.

답변

0

주어진 메뉴 항목에 대한 정보를 검색하는 기존의 API 방법이 없습니다.이 정보는 거의 필요하지 않으며 확장 프로그램의 개발자가 이미 사용할 수 있기 때문입니다.

다음은 결과 달성하기 위해 범용 기능입니다 :

/** 
* Creates a menu item using chrome.contextMenus.create. 
* When the second argument is specified, the click handler receives a 
* third argument: The original creation data. 
* When the "onclick" property is set in the creationData, the "onclick" 
* event does not receive a third parameter. 
* 
* @param object creationObject Basic creation object 
* @param function onclickHandler "click" property of the creationObject 
*/ 
function createMenuItem(creationObject, onclickHandler) { 
    if (onclickHandler) { 
     creationObject.onclick = function(onClickData, tab) { 
      onclickHandler(onClickData, tab, creationObject); 
     }; 
    } 
    return chrome.contextMenus.create(creationObject); 
} 

// Usage: 
createMenuItem({"title": "sometitle", "contexts":["selection"]}, searchSelection); 
function searchSelection(info, tab, creationData) { 
    var query = "<i want title " + creationData.title + " here>" + info.selectionText; 
    var url = "http://www.google.com/search?q=" + query; 
    chrome.tabs.create({url: url}); 
} 

을 그리고 아니, 인라인 편집 할 메뉴 항목을 (사용할 수있는 유일한 옵션은 the documentation, chrome.contextMenus.create에 언급 된)을 추가 할 수있는 방법이 없습니다.

+0

고마워,하지만 나를 위해 일하는 wasnt, contextmenu 항목 doest 나열 : ( –

+0

어쨌든, 내가이 기능을 원했기 때문에, 내가 그걸로 줄을 저장할 수있는,이 확장은 간단한 구글 dorks 실행기이며, 내가 얻을 수 있다면 제목, 다음 제목이 'site : techpowerup.com'이면 하나의 함수로 충분합니다. title + selectionText -> results'site : techpowerup.com selectionText'. 이제 4 개의 함수가 있습니다. 1 -1 다른 사이트에 대해. 대답은 고맙습니다.) –

+1

@ Jim-Y 코드에 오타가있었습니다. 나는}로 바꿨다. 이제는 효과가있다. –

관련 문제