通过content script选取HTML框内容
在通过content script改变web页面中只是简单的增加灰色的边框,还不具有生产意义。这里提出一个需求,就是选取某个html框内的内容。那么需要让这个框是带灰色边框的,另外,双击这个框内区域,弹出警告对话框,并显示框内的html文本信息。类似这样:
和通过content script改变web页面的区别是只允许选中的框是带灰色边框的,它的外层框不带灰色边框。
因为使用jquery,只需在main.js中增加几行代码即可:
var target=null;
$("*").mouseenter(function(e){
if(target!=null){
$(target).css("border", "");
$(target).unbind(‘dblclick’);
}
target=e.target;
$(target).css("border", "1px solid gray");
$(target).dblclick(function(){
window.alert("选择的是:"+$(target).html());
});
});$("*").mouseleave(function(){
$(this).css("border", "");
$(this).unbind(‘dblclick’);
});
这篇文章上的评论的 RSS feed TrackBack URI