可以将文件从桌面拖动到Firefox 3.5中的放置区域并启动上传? [英] Can I drag files from the desktop to a drop area in Firefox 3.5 and initiate an upload?

查看:148
本文介绍了可以将文件从桌面拖动到Firefox 3.5中的放置区域并启动上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的放置区域设置了一个ondrop事件,当我将图像从桌面拖动到放置区域时,它会收到一个事件。

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.

然而,根据到Recommended_Drag_Types文件:

However, according to the Recommended_Drag_Types document:

https: //developer.mozilla.org/en/DragDrop/Recommended_Drag_Types


使用application / x-具有nsIFile对象的数据值的moz-file类型。非特权网页无法检索或修改此类型的数据。

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.

这是有道理的,但是如何提示用户升级权限以获取访问文件数据,并通过 XMLHttpRequest 发送它。

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返回此错误:

Javascript returns this error:

Permission denied for domain.com to create wrapper for object of class UnnamedClass

我可以找到的唯一的文章是2005年的一篇,但是我无法确定这些方向是否仍然适用于Firefox 3,建议您执行以下操作:

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');

似乎不起作用。

推荐答案

我发现如果不是全局升级特权:

I found out that if instead of escalating privileges globally:


    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    ...
    function doDrop(event) {
       ...
       var file = event.dataTransfer.mozGetDataAt("application/x-moz-file", 0);
       ...
    }

我在功能体内升级权限:

I escalate privileges in the function's body:


    ...
    function doDrop(event) {

       netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
       ...
       var file = event.dataTransfer.mozGetDataAt("application/x-moz-file", 0);
       ...
    }

我摆脱了您所描述的错误,并获得对 nsIFile 实例我正在寻找。

I get rid of the error you described and gain access to the nsIFile instance I was looking for.

这篇关于可以将文件从桌面拖动到Firefox 3.5中的放置区域并启动上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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