Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a local pdf and I try load this pdf in an iframe by the path of the file.

The file has a name 明星.pdf and the path is like this: http://localhost:8080/path-here/明星.pdf

When I try open the pdf file, the browser do this request and fails (404): http://localhost:8080/path-here/%E6%98%8E%E6%98%9F.pdf

The problem only occurs with pdfs that contains chinese characteres.

Any suggestion?

PS: I'm using javascript.

Edit:

Example:

//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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
211 views
Welcome To Ask or Share your Answers For Others

1 Answer

Javascript can handle most non-english characters, but you'll probably need to encode them for the web browser to recognise them. Try specifying the webpage (server?)'s charset as UTF-8

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

You'll likely also need to prepare your string for the webbrowser, I suggest using encodeURIcomponent() or encodeURI(). Here's an explanation of the function https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent. Hope that helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...