Adding an icon to content & handling its events
I am trying to use this code but i dont know the exact class for google search results that would replace "the_search_result_class". Please help me to find out Dom class for google search results on google search page.
function someFunction() {
alert("The user clicked on the icon.")
}
var icon = document.createElement("img");
icon.src = chrome.extension.getURL("icon.png");
var searchResults = document.getElementsByClassName("the_search_result_开发者_StackOverflow社区class")
for (var i = 0; i < searchResults.length; i++) {
var searchResultIcon = icon.cloneNode();
searchResultIcon.addEventListener("click", someFunction, false);
searchResults[i].append(searchResultIcon);
}
To find out a dynamic class name on a page:
- Open developer console (Ctrl+Shift+J)
- Click on "Elements" tab and then on the magnifying glass icon
- Select element you are interested in on a page and you will see its html source below.
精彩评论