Firefox扩展程序在文档中显示图像 [英] Firefox Extension display image in document

查看:81
本文介绍了Firefox扩展程序在文档中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不违反安全性约束的情况下在当前文档中显示本地图像.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆