1

这是我在名为“detectclicks.js”的内容脚本中放入的 js 代码,用于检测在浏览器中打开的网页的任何部分的点击 - 它使用 Jquery --- 但是没有显示警报......

$('body').on('click', '*', function(event) {
     window.alert(' ID of element- testing'); 
    window.alert(' ID of element=' + $(this).attr('id'));  // Get ID attribute
    window.alert(' ID of Parent element=' + $(this).parent()..attr('id'));
});

这是我的 manifest.json——

{
  "name": "My First Extension",
  "version": "1.0",
  "manifest_version": 2,
  "content_scripts": [
      {
        "matches": ["<all_urls>"],
        "js": ["jquery1.7.2.js", "detectclicks.js"]
      }
   ],
   "description": "The first extension that I made.",
   "browser_action": {
   "default_icon": "icon.png",
   "default_popup": "popup.html"
    } 
}

当我将此扩展程序加载到谷歌浏览器并访问网页时,没有显示任何警报..单击页面的任何部分...我在这里做错了什么?

4

1 回答 1

4

正如评论中所讨论的,检查它不应该是这一行中的双点:

window.alert('ID of Parent element=' + $(this).parent().attr('id'));

留心!;)

于 2012-06-02T23:51:29.657 回答