Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome 检测鼠标点击类似facebook的按钮(来自chrome扩展)_Google Chrome_Google Chrome Extension_Facebook Like - Fatal编程技术网

Google chrome 检测鼠标点击类似facebook的按钮(来自chrome扩展)

Google chrome 检测鼠标点击类似facebook的按钮(来自chrome扩展),google-chrome,google-chrome-extension,facebook-like,Google Chrome,Google Chrome Extension,Facebook Like,我正在开发一个chrome扩展,当用户点击类似facebook的按钮时,它会显示一个警报 我使用jQuery就是为了这个目的,但它不起作用 这是密码 $("button").click(function(){ alert("Like"); }); 我也尝试了这段代码,因为like按钮在iframe中,但仍然没有成功 var abc = $(document).find('iframe:first').contents().find('html:first').find('body:first'

我正在开发一个chrome扩展,当用户点击类似facebook的按钮时,它会显示一个警报

我使用jQuery就是为了这个目的,但它不起作用

这是密码

$("button").click(function(){
alert("Like");
});
我也尝试了这段代码,因为like按钮在iframe中,但仍然没有成功

var abc = $(document).find('iframe:first').contents().find('html:first').find('body:first');
abc.find("button").click(function(){
alert("Like");
});
manifest.json(我向该文件添加了权限)


非常感谢任何帮助???

第一个问题可能是,在大多数情况下,“like”是一个
而不是一个按钮,因此
$(“按钮”)
不会选择它。至于检测被点击的
链接,只需以下内容:

manifest.json

 "permissions": [
   "tabs","*://*.facebook.com/*"
 ],
 "content_scripts": [{
   "matches": ["*://*.facebook.com/*"],
   "js": ["jquery.js","click.js"]
 }]
点击.js

// For most of the likes on things such as comments and pictures and all that
$('a.UFILikeLink').click(function(){
  console.log('Like link was clicked somewhere');
});
// For the Like 'Button' that can be found on pages 
$('input[value="Like"]').click(function(){
  console.log('Like button was clicked somewhere');
});

我复制了u在上面发布的相同代码,还包括jquery.js,但当我单击“like button”时,什么都没有发生。没有日志。我还将console.log替换为alert(),但仍然没有发生任何事情。@WaqasAhmed表示,其中一个是
,值为
,类似于
,我已经更新了我的答案,将它们也包括在内。
// For most of the likes on things such as comments and pictures and all that
$('a.UFILikeLink').click(function(){
  console.log('Like link was clicked somewhere');
});
// For the Like 'Button' that can be found on pages 
$('input[value="Like"]').click(function(){
  console.log('Like button was clicked somewhere');
});