简体   繁体   English

使用Chrome扩展程序检测点击

[英]Detecting clicks with a Chrome Extension

Find myself writing an extension for Chrome, as a test I want to make this happen: 找到我自己写的Chrome扩展程序,作为测试,我想做到这一点:

$(document).click(function(e) { alert('clicked'); });

But it does not work as expected, any ideas? 但这不能按预期工作,有什么想法吗?

This is manifest.json: 这是manifest.json:

"name": "Test",
  "version": "0.2",
   "content_scripts": [
    {
      "all_frames": true,
      "matches": ["*://mail.google.com/mail/*"],
      "js": ["jquery-1.7.2.js", "test.js"]
    }
  ]
$(document).click(function(e) { var evt=e||window.event;if(evt.type=='click')alert('clicked'); });

Here is what you are missing! 这就是你所缺少的!

DEMO 演示

I think you should use .on() it worked for me. 我认为您应该使用对我有用的.on() Simple example: $(document).on("click",function(){alert("clicked")});​​​​​​​​​​​​​​​​​ 简单的例子: $(document).on("click",function(){alert("clicked")});​​​​​​​​​​​​​​​​​

For all options of .on look here http://api.jquery.com/on/ 有关.on所有选项,请.on http://api.jquery.com/on/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM