2010-05-05 31 views
2

For an Intranet web application (document management), I want to show a list of files associated with a certain customer. The resulting HTML is like this:請確保<a href="local file"> is opened outside of browser

<a href="file:///server/share/dir/somefile.docx">somefile.docx</a> 
<a href="file:///server/share/dir/someotherfile.pdf">somefile.pdf</a> 
<a href="file:///server/share/dir/yetanotherfile.txt">yetanotherfile.txt</a> 

This works fine. Unfortunetly, when clicking on a text file (or image file), Internet Explorer (and I guess most other browsers as well) insist on showing it in the browser instead of opening the file with the associated application (e.g. Notepad). In our case, this is undesired behavior, since it does not allow the user to edit the file.

Is there some workaround to this behavior (e.g. something like <a href="file:///..." open="external">)? I'm aware that this is a browser-specific thing, and an IE-only solution would be fine (it's an Intranet application after all).

+0

PS:在服務器上打開文件並使用「Content-disposition:attachment」進行流式傳輸不是一種選擇,因爲這隻允許用戶編輯文件的本地副本。 – Heinzi 2010-05-05 13:51:27

+0

即使用戶可以在適當的應用程序中直接打開文件,該文件仍然只是本地副本。 – dnagirl 2010-05-05 14:10:21

+0

@dnagirl:不,它不是。至少IE足夠聰明*不*下載本地文件副本,而是將UNC路徑發送到應用程序。 – Heinzi 2010-05-05 15:24:39

回答

1

Do you WANT people to just mess around with things lying on your server? That reeks of lack of security to me...

I'd recommend letting the user check it out locally and using a database or similar to allow people to check in new drafts. Said drafts should be verified and validated somehow before they are actually written to the server's filesystem.

+2

是的,這是一個要求。這是一個適用於小公司的軟件,通用文件位於網絡共享位置,所有文件都可以「就地」編輯。文件訪問由NTFS權限管理。 – Heinzi 2010-05-05 14:03:44

0

I just tested this and it seems to work (IE6, not in FF or Chrome):

<HTML> 
<script language="JavaScript"> 
    function startWord(strFile) 
    { 
    var myApp = new ActiveXObject("Word.Application"); 
    if (myApp != null) 
    { 
     myApp.Visible = true; 
     myApp.Documents.Open(strFile); 
    } 
    } 
</script> 
<a href="javascript:startWord('file:///server/share/dir/test.doc')">test.doc</a>. 

Found it here

+0

謝謝,但Word文件不是這裏的問題。問題是文本文件,圖像文件和IE可以內聯顯示的任何其他類型的文件。 – Heinzi 2010-05-05 15:25:31

+0

你應該看到我引用的鏈接。它有其他文件類型/程序關聯。至少我可以讓你指出正確的方向。另一種選擇是編寫自定義協議,但這需要在本地計算機上安裝或註冊。 – 2010-05-06 14:20:29