我可以将文件从桌面拖到 Firefox 3.5 中的放置区域并启动上传吗?
我在放置区域设置了一个 ondrop 事件,当我将图像从桌面拖动到放置区域时,它会收到一个事件。
但是,根据Recommended_Drag_Types文档:
https://developer.mozilla.org/en/DragDrop/推荐的_Drag_Types
使用 application/x-moz-file 类型和 nsIFile 对象的数据值来拖动本地文件。 非特权网页无法检索或修改此类数据。
这是有道理的,但我如何提示用户升级权限以访问文件数据并通过 XMLHttpRequest
发送它?
如果我在执行以下代码时尝试在不升级权限的情况下执行此操作:
event.dataTransfer.mozSetDataAt("application/x-moz-file", file, 0);
Javascript 返回此错误:
Permission denied for domain.com to create wrapper for object of class UnnamedClass
我能找到的唯一一篇关于此的文章是 2005 年的一篇,但我无法判断这些说明是否仍然适用于 Firefox 3,建议这样做:
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
这似乎不起作用。
I've set a ondrop event on my drop area and it receives an event when I drag an image from my desktop to the drop area.
However, according to the Recommended_Drag_Types document:
https://developer.mozilla.org/en/DragDrop/Recommended_Drag_Types
A local file is dragged using the application/x-moz-file type with a data value that is an nsIFile object. Non-privileged web pages are not able to retrieve or modify data of this type.
That makes sense, but how do I prompt the user to escalate privileges to get access to the file data and send it via an XMLHttpRequest
?
If I try it without escalating privileges when I do this code:
event.dataTransfer.mozSetDataAt("application/x-moz-file", file, 0);
Javascript returns this error:
Permission denied for domain.com to create wrapper for object of class UnnamedClass
The only article I can find on this is one from 2005 but I can't tell if the directions still apply to Firefox 3, it suggest doing this:
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
which doesn't seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尚未升级到 3.5,可以使用 dragdropupload 扩展。
If you haven't upgraded to 3.5 yet, you can use the dragdropupload extension.
我发现,如果不是全局升级权限:而是
在函数主体中升级权限:
我摆脱了您描述的错误并获得对我正在寻找的 nsIFile 实例的访问权限。
I found out that if instead of escalating privileges globally:
I escalate privileges in the function's body:
I get rid of the error you described and gain access to the
nsIFile
instance I was looking for.