2015-01-06 3 views
2

현재 마우스로 마우스를 올리고있는 요소의 ID를 가져와야하는 크롬 확장 프로그램을 만들고 있습니다. 본질적으로, 마우스가 버튼 위에 있고 키보드 단축키를 사용하면 버튼의 ID와 함께 경고를 표시 할 수 있어야합니다. 여기 Chrome 확장 프로그램 : 마우스로 HTML 요소를 클릭하는 방법

내가 할 것으로 예상하고있어 무엇 :

의 manifest.json에게

"commands": { 
    "Display ID": { 
     "suggested_key": { 
      "default": "Ctrl+Shift+1", 
      "mac": "Command+Shift+1" 
     }, 
     "description": "Display ID" 
    }, 

background.js을

chrome.commands.onCommand.addListener(function(command) { 

    // Get the active tab when the command was fired 
    chrome.tabs.query({active:true, currentWindow: true}, function(arrayOfTabs) { 
     currentTabId = arrayOfTabs[0].id; 
    }); 

    // Display the ID of the HTML element where the mouse is currently hovering 
    alert("This is the element's id:" + elementId); // How to do this part??? 

}); 

이 가능인지 아닌지 알려주세요 !!!

답변

0

내 질문에 대한 답변을 찾았습니다. 나는 현재 변수에 hound되어있는 요소를 저장하고 키보드 단축키 명령이 실행될 때 그것을 호출했다. 본질적으로 나는 마우스 오버 이벤트 리스너를 배치하여 현재 요소를 추적했습니다.

관련 문제