在Addon SDK上使内容可访问 [英] Making content accessible on Addon SDK

查看:170
本文介绍了在Addon SDK上使内容可访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firefox的Addon SDK开发插件(1.11)。我的扩展动态地在每个网站上创建一个iframe,然后从加载的本地目录加载一个包含其他资源(如图像,字体文件等)的html文件。
$ b

问题

当加载任何这样的本地资源时(例如: resource:// 模式),iframe无法显示它们并引发消息:

lockquote

安全性错误:http://www.XXX上的内容可能无法加载或链接到
资源:// XXX


这是在Firefox 3上引入了 安全措施。在不使用Addon SDK的情况下进行开发时,解决方法是使用contentaccessible = yes声明一个目录,使任何人都可以访问该目录的内容,包括我的add。但是,我一直无法使用Addon SDK找到类似的功能。有没有更好的方式来使用我的插件创建并插入到页面的iframe上的本地数据?

我不'不要以为你可以直接加载一个指向URL内部资源的iFrame。浏览器抱怨,因为它要么违反相同的原产地政策或跨站点脚本之一。我不记得现在哪一个。如果是要加载的html内容,您可以随时将其注入到DOM中,然后使用events API将消息发送到文档对象以显示您的自定义html 。我已经做了这个过去,它的工作。所以从main.js发送消息到内容脚本,然后将您的iframe html注入到DOM,然后您可以发送文档对象的消息来显示它。



我希望这有助于。


I am developing an addon using Firefox's Addon SDK (v. 1.11). My extension dynamically creates an iframe on each website and then loads an html file which includes other resources such as images, font files, etc. from the add on's local directory.

Problem

When loading any of such local resources (i.e.: "resource://" schema), the iframe fails to display them and a message is thrown:

Security Error: Content at http: //www.XXX may not load or link to resource://XXX

This is a security measure introduced on Firefox 3. When developing without the Addon SDK, the way around it is declaring a directory with "contentaccessible=yes", making the directory's contents accessible to anyone, including my add on. However, I have not been able to find similar functionality using the Addon SDK. Is there a better way of using local data on an iframe that my addon creates and inserts into a page?

解决方案

I don't think you can directly load an iFrame that points to a resource inside your URL. The browser complains because it's either breaking same origin policy or cross site scripting one. I can't remember which one right now.

if it is html content you want to load you can always inject it into the DOM and then send a message to the document object using the events API to display your custom html. I've done this in the past and it works.

so from main.js send a message to content script which will then inject your iframe html into the DOM and then you can send the document object a message to display it.

I hope this helps.

这篇关于在Addon SDK上使内容可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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