admin管理员组

文章数量:1394164

inspired from Google dictionary plugin

Chrome extension : How to get / detect click events on any page or any where. just like Google Dictionary Plugin does?

eg. click on a table or a form etc.

Here is the code ,

$(".myTable").on('click', 'tr', function () {
var trValue = $(this).attr('value');
var tdValue = $(this).children('td').map(function (index, val) {
        return $(this).text();
    }).toArray();
console.log(tdValue);});

inspired from Google dictionary plugin

Chrome extension : How to get / detect click events on any page or any where. just like Google Dictionary Plugin does?

eg. click on a table or a form etc.

Here is the code ,

$(".myTable").on('click', 'tr', function () {
var trValue = $(this).attr('value');
var tdValue = $(this).children('td').map(function (index, val) {
        return $(this).text();
    }).toArray();
console.log(tdValue);});
Share Improve this question edited Mar 4, 2016 at 6:10 K.Karthik asked Mar 4, 2016 at 5:48 K.KarthikK.Karthik 31 silver badge4 bronze badges 3
  • 1 what u have done so far? – xkeshav Commented Mar 4, 2016 at 5:52
  • The below code is for getting data from a table. my requirement is , I should be able to get data from any table of any page in any tab. $(".myTable").on('click', 'tr', function () { var trValue = $(this).attr('value'); var tdValue = $(this).children('td').map(function (index, val) { return $(this).text(); }).toArray(); //alert(tdValue); });*/ – K.Karthik Commented Mar 4, 2016 at 6:01
  • @K.Karthik, hi, if my answer has helped, please consider accepting the answer, thanks – Haibara Ai Commented Mar 8, 2016 at 2:26
Add a ment  | 

1 Answer 1

Reset to default 6

You could use content script, remember to set "matches": ["<all_urls>"] in manifest.json, it means you content script will be injected into every page.

In your content script, you can listen to click event and do what you want

document.addEventListener("click", function() {
    // Do what you want with click event
}, false);

本文标签: