$(document).click()在chrome扩展中不起作用 [英] $(document).click() not working in chrome extension

查看:704
本文介绍了$(document).click()在chrome扩展中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个chrome插件,它显示了我在页面底部添加的div标签中的网页上单击的元素。
当我点击浏览器动作时,插件显示为我设计的底部。但脚本中的其他部分无法正常工作,

I am creating a chrome plugin , which shows the elements which are clicked on a web page in a div tag I have added at the bottom of the page. The plugin is showing up as I designed at the bottom , when i click on browser action. But the other part of the script with in the script is not working,

我真的对chrome -plugins很陌生,拜托他

I am really new to chrome -plugins , please he

manifest.json

manifest.json

   {
"name": "Iframe",
"description": "",
"version": "1",
"manifest_version": 2,
 "background":{
    "scripts":["background.js"]
},
 "browser_action": {
"default_title": "Make this page red"
 },
       "permissions": [
    "<all_urls>"
]
}

myscript.js

myscript.js

   var iframe = document.createElement("iframe");
    var div = document.createElement("div");
   div.setAttribute("src", "");
   div.setAttribute("style", "position:fixed; z-index:10000;bottom:0px;left:0px; border:none; width:100%; height:100px; background-color:#ccc;border:#000 solid 3px;");
  div.setAttribute("scrolling", "no");
  div.setAttribute("frameborder", "0");
  div.setAttribute("id","ospy");
  var domEl= "test56";
  document.body.appendChild(div);
  document.getElementById('ospy').innerHTML += domEl;

  //this part of the code is not working
 $(document).click(function(e) {
 e.preventDefault();
     var domEl = e.target.id.toString();
 domEl += e.target.className.toString();
 domEl += e.target.toString();
 domEl += e.target.innerHTML;

     document.getElementById('ospy').innerHTML += domEl;

});


推荐答案

我得到了解决方案,

它是添加点击到文档的事件监听器,

It is to add click to event listener of the document ,

 document.addEventListener("click", 
    function (e) {
        e.preventDefault();
 var domEl = e.target.id.toString();
 domEl += e.target.className.toString();
 domEl += e.target.toString();
 domEl += e.target.innerHTML;*/

 document.getElementById('ospy').innerHTML += domEl;
    }, 
    false);

这篇关于$(document).click()在chrome扩展中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆