Browser does not use utf-8 but meta tag is set

2019-05-31 14:39发布

This is my page header:

<!DOCTYPE html> 
<html> 
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
...

As you can see the charset is set to utf-8 but Chrome/Firefox does not print the page as utf-8. I guess that is because the server sends this header:

Content-Type:text/html; charset=ISO-8859-15

How can I overwrite this header from my html page?

3条回答
Viruses.
2楼-- · 2019-05-31 15:16

You can't overwrite the charset from your html page. Things to look for:

  1. Your web server may be configured with a default charset. See if you can change it. Be warned: this may be a global setting that would affect all files of a specific Content-Type.

  2. Despite the fact that you've literally typed charset=UTF-8 into your html document, your IDE/text editor may still be saving it with a different character encoding. If your using *nix, you can check the file encoding on any file on the command line like this:

    file -I filename.html
    

    If the output of that command reports something other than UTF-8 or us-ascii, you should go back to your IDE/text editor and figure out how to set the character encoding on the files it saves as UTF-8. Your web server may be auto detecting the character encoding and setting headers accordingly.

查看更多
一夜七次
3楼-- · 2019-05-31 15:27

You can't.

HTTP headers have priority over meta elements that claim to be equivalent.

Fix your server settings so it sends the correct content-type.

查看更多
霸刀☆藐视天下
4楼-- · 2019-05-31 15:38

You can change the server header by adding an .htaccess file containing:

AddDefaultCharset UTF-8
查看更多
登录 后发表回答