开发者

Adding an icon to content & handling its events

开发者 https://www.devze.com 2023-02-09 17:48 出处:网络
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

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:

  1. Open developer console (Ctrl+Shift+J)
  2. Click on "Elements" tab and then on the magnifying glass icon
  3. Select element you are interested in on a page and you will see its html source below.
0

精彩评论

暂无评论...
验证码 换一张
取 消