我正在创建一个chrome插件,它显示了我在页面底部添加的div标签中的网页上单击的元素。 当我点击浏览器操作时,插件显示为我在底部设计的。但脚本中脚本的另一部分无效,
我是chrome -plugins的新手,请他
的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
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;
});
答案 0 :(得分:1)
我得到了解决方案,
将点击添加到文档的事件监听器
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);