我正在尝试开发一个firefox扩展,它在每个网页的底部绘制一个工具栏。
直到现在,我设法使jQuery工作,并通过运行
$("body",mr.env).css("background","black"); 在mr.on=function().中
这段代码只会使网页的背景色变成黑色,每当我单击与该副词相关的菜单项时。
但是,如果我想跑
$('body',mr.env).append( ' <img src="img/check.png" /> ' ); 只是失败了。它不会显示错误控制台中的任何错误,也不会显示图像。
为什么会这样呢?
这是我的覆盖XUL:
<script src="window.js"/>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<!-- Firefox Tools menu -->
<menupopup id="menu_ToolsPopup">
<menuitem id="menu_crypt_demo" class="" image=""
label="Use DnsResolver?" insertbefore="javascriptConsole" accesskey="o"
oncommand="DnsResolver.onMenuItemCommand(event);">
</menuitem>
</menupopup>
这是JavaScript文件(window.js)
var DnsResolver = {
onLoad: function() {
// initialization code
this.initialized = true;
},
onMenuItemCommand: function() {
testextension.on();
window.open("chrome://dnsresolver/content/window.xul", "", "chrome");
}
};
window.addEventListener("load", function(e) { DnsResolver.onLoad(e); }, false);
if(!testextension){ var testextension={};}
(function(){
var mr=testextension;
mr.on=function(){
mr.loadLibraries(mr);
var jQuery = mr.jQuery;
var $ = function(selector,context){ return new jQuery.fn.init(selector,context||window._content.document); };
$.fn = $.prototype = jQuery.fn;
mr.env=window._content.document;
/*$("body",mr.env).css("background","black");*/
$('body',mr.env).append('<img src="img/check.png" />');
$(mr.env).ready(function(){
// hide and make visible the show
$("span.close a",mr.env).click(function() {
$("#tbar"),mr.env.slideToggle("fast");
$("#tbarshow",mr.env).fadeIn("slow");
});
// show tbar and hide the show bar
$("span.show a",mr.env).click(function() {
$("#tbar",mr.env).slideToggle("fast");
$("#tbarshow",mr.env).fadeOut();
});
});
/*$("body",mr.env).css("background","black");*/
}
// Loading the Jquery from the mozilla subscript method
mr.loadLibraries = function(context){
var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://dnsresolver/content/jquery-1.4.4.min.js",context);
var jQuery = window.jQuery.noConflict(true);
if( typeof(jQuery.fn._init) == 'undefined') { jQuery.fn._init = jQuery.fn.init; }
mr.jQuery = jQuery;
}
})();发布于 2011-02-15 23:54:23
从Firefox 3开始,不能再从<img>、<script>或包含在或添加到从不受信任源加载的内容中的其他元素中引用铬资源。此限制既适用于不受信任源定义的元素,也适用于由受信任扩展添加的元素。如果需要显式地允许这样的引用,请将内容可访问标志设置为yes,以获得在旧版本火狐中找到的行为。
发布于 2011-02-14 23:59:52
使用FireFox中的HTML来知道是否添加了img元素。它可能是添加的,问题在于您的URL。
我记得在构建我的FireFox扩展名时,文件是通过一个特殊的协议(chrome://我认为)定位的,您可以在其中放置扩展名并浏览它。
https://stackoverflow.com/questions/4994510
复制相似问题