2016-01-18 46 views
-1

我有一個本地pdf,我嘗試通過該文件的路徑在iframe中加載此pdf。從url中加載一個帶有中文文件名的pdf

文件有一個名明星.pdf和路徑是這樣的: http://localhost:8080/path-here/明星.pdf

當我嘗試打開PDF文件時,瀏覽器做這個請求和失敗(404): http://localhost:8080/path-here/%E6%98%8E%E6%98%9F.pdf

只有包含中文字符的pdf纔會出現問題。

有什麼建議嗎?

PS:我正在使用javascript。

編輯:

例子:

//there's a http:// in front, I can't put more links in post 
var url = 'localhost:8080/path-here/teste.pdf' 
var url2 = 'localhost:8080/path-here/明星.pdf' 

window.open(url,"_blank") //works fine 
window.open(url2,"_blank") //fails 
+0

我看到'javascript'在你的問題標籤。你會顯示一些代碼嗎? –

回答

1

的JavaScript可以處理大部分非英語字符,但你可能需要它們編碼的Web瀏覽器來識別它們。嘗試指定網頁(服務器?)的字符集爲UTF-8

<head> 
    <meta charset="UTF-8"> 
    </head> 

你可能還需要準備您的字符串的網頁瀏覽器,我建議使用encodeURIComponent方法()是encodeURI() 。以下是對功能 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent的解釋。希望有所幫助!

+0

我試過了,同樣的問題 –

+0

http://www.faqs.org/rfcs/rfc1738.html RFC 1738說不要在網址中使用非ASCII字符,這就是爲什麼你有這個問題(不常見的用例) 。你使用什麼服務器/設置?請確保您的URIEncoding也設置爲UTF-8 –

+0

http://tools.ietf.org/html/rfc3987 RFC3987引入了IRI,如果您想要更長久的修復,可以使用未編碼的UTF-8。不知道他們是否可以在JavaScript中使用,但你必須做一些研究。 –

0

你可以像這樣,使用

<a href="yourfilepath" download="your_chinesefilename.pdf", 

例:

<a id="dlink" style="display:none;"></a> 
<button onclick="downloadWagePdf()"> 
    pdfdownloadceshi 
</button> 
<script type="text/javascript"> 

    function downloadWagePdf() { 
     var pdfFilePath = "<%=basePath%>" + "WebRoot\\download\\" + "bank_wage" + ".xls"; 
     var titleDate= new Date().Format("yyyy-MM-dd hh-mm-ss"); 
     document.getElementById("dlink").href = pdfFilePath; 
     document.getElementById("dlink").download = "銀行流水錶"+titleDate+".xls"; 
     document.getElementById("dlink").click(); 
    } 

</script> 

你可以看看this url,如何使用下載

相關問題