2009-07-01 31 views
1

我在拖放區域設置了一個ondrop事件,當我從桌面拖動圖像到拖放區域時,它會收到一個事件。我可以將文件從桌面拖到Firefox 3.5中的拖放區域並啓動上傳嗎?

然而,根據Recommended_Drag_Types文件:

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.

這是有道理的,但我怎麼提示用戶提升權限以訪問文件數據,並通過發送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'); 

其中d似乎沒有工作。

+0

你找到了答案嗎?我希望能夠至少捕獲本地網址。有任何想法嗎? thx男人 – 2009-11-12 04:17:13

+0

它現在可能!看到我的答案:http://stackoverflow.com/a/33431704/195216 – dforce 2015-10-30 08:40:45

回答

0

如果您還沒有升級到3.5版,您可以使用dragdropupload擴展名。

+0

謝謝,但我從更多的Web開發人員的角度思考這個問題,我認爲大多數人會升級到Firefox v3.5,但會少得多安裝了這個擴展。 – bertrandom 2009-07-01 09:04:49

0

我發現,如果不是全球不斷升級的特權:

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

我升級的函數體特權:

 
    ... 
    function doDrop(event) { 

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

我擺脫錯誤的,你描述並獲得了nsIFile我正在尋找的實例。