Firefox扩展程序在文档中显示图像 [英] Firefox Extension display image in document
问题描述
是否可以在不违反安全性约束的情况下在当前文档中显示本地图像.
Is it possible to display local image in current document without violating the security constraints.
示例:图像位于chrome://myExtension/content/2.png
$myImg=jQuery("#myImg", doc);
$myImg.attr("src","chrome://beSure/content/2.png");
错误控制台:安全错误: https://上的内容www.google.com/accounts/ServiceLogin?....&from=login 可能无法加载或链接到chrome://myExtension/content/2.png.
Error Console: Security Error: Content at https://www.google.com/accounts/ServiceLogin?....&from=login may not load or link to chrome://myExtension/content/2.png.
使用非本地链接的工作示例:
Working example with non-local link:
$myImg=jQuery("#myImg", doc);
myImg.attr("src","http://cdn1.iconfinder.com/data/icons/classic-cars-by-cemagraphics/128/minicar_128.png");
图片来自有效的网址,这样就可以了.但是如何显示本地图像?
Image comes from valid url so that is ok. But how can i display local image ?
推荐答案
您的chrome程序包需要在chrome.manifest
中用contentAccessible
标志声明,请参见
Your chrome package needs to be declared with the contentAccessible
flag in the chrome.manifest
, see documentation. By default, web pages are no longer allowed to load images from chrome://
, this previously allowed web pages to detect installed extensions by loading their images.
另一种可能性应该是使用image.src
属性而不是设置属性:
The other possibility should be using image.src
property instead of setting the attribute:
var myImg = doc.getElementById("myImg");
myImg.src = "chrome://beSure/content/2.png";
这应该起作用,因为您的(特权)脚本在此处直接设置图像位置.另一方面,属性更改是异步处理的,因此可以使用网页的权限来完成.
This should work because here your (privileged) script is setting image location directly. Attribute changes on the other hand are processed asynchronously, so this is done with the privileges of the web page.
这篇关于Firefox扩展程序在文档中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!