UTF-8 issue in Firefox - response header overridin

2020-04-11 11:05发布

I have a page with the following meta tag:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

I thought this would set the default character set to UTF-8 and indeed it appears to in Chrome and Safari, but not in Firefox.

I have a PHP script on the page which generates a playlist of audio files for jPlayer, and filenames with accents in characters aren't working/playing in Firefox.

Here is the error message I am seeing in the Firebug console:

enter image description here

As you can see the characters in the filename aren't getting read correctly. The filename should be "Guessi-Guéré-Guessi (Pop Bariba)"

When I then look for more detail on the error, under the "Headers" tab I see this:

enter image description here

Which shows that the charset is iso-8859-1. Then in the "Response" tab I see:

enter image description here

Which confirms the error, but this time with the correct encoding showing. The file definitely exists, and as I say it plays/works in other browsers.

So I am presuming the issue is to do with the response headers getting set differently in Firefox, and overriding the meta tag. I have checked the response headers in Chrome, and they are indeed set to UTF-8. What can I do to fix this?

2条回答
▲ chillily
2楼-- · 2020-04-11 11:43

The URL alias http://monthlymixup.com/mixups/july_2012/media/nick/Guessi-Gu%C3%A9r%C3%A9-Guessi%20%28Pop%20Bariba%29.mp3 works OK on Firefox, too. So the problem is appearently on the linking page. The problem can be reproduced using the following test page:

<!doctype html>
<title></title>
<meta charset=iso-8859-1>
<a href=
"http://monthlymixup.com/mixups/july_2012/media/nick/Guessi-Gu%e9r%e9-Guessi%20%28Pop%20Bariba%29.mp3"
>link</a>

Thus, the problem is in the PHP code that generates the linking page. It seems to % encode the letter “é” on its own, using the ISO-8859-1 based encoding %e9 instead of the proper UTF-8 based encoding.

Make sure that the linking page is generated correctly, with the letter “é” rather than any % encoded form or the UTF−8 based encoding %C3%A9.

查看更多
混吃等死
3楼-- · 2020-04-11 11:51

It turns out that there was an issue with the Flash fallback in jPlayer. Firefox uses Flash to play the mp3.

Here's the fix from the developer of jPlayer:

Use the encodeURI(url) JavaScript command to encode the URL in JavaScript before passing the url to setMedia. For example:

$ ("#id").jPlayer("setMedia", {
   mp3: encodeURI("http://domain.com/audio/大地書房.mp3")
});
查看更多
登录 后发表回答