[英]$(document).click() not working in chrome extension
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. 我正在创建一个chrome插件,该插件显示了我在页面底部添加的div标签中在网页上单击的元素。 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, 但是该脚本中包含脚本的另一部分无法正常工作,
I am really new to chrome -plugins , please he 我真的是chrome插件的新手,请他
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;
});
I got the solution , 我找到了解决方案,
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.