Saturday 28 January 2017

html - Can I make browsers choose UTF-8 for viewing source code?




I put up some source code files for viewing on the web. The problem is, browsers tend to not understand that these files are in UTF-8, and I wonder if there's anything I can do about that. (I'm sure some browsers use UTF-8 per default, but Safari at least doesn't. I have to go into the View menu and choose the encoding manually to make it look right.)



My set of webpages is here, with several Python files and one C file: fgcode.avadeaux.net. I tried putting a charset="UTF-8" attribute in the a elements in the , but that doesn't seem to help. The Python files declare the charset in a comment on the top line, but the browser ignores that as well (which is no surprise, it's not a Python source code browser after all).



I don't have much control over the web server, it's run by my ISP and I just put the files there. But I'd still be interested to know if this problem has a web server configuration solution.



Solution: solved, as per links provided, by adding an .htaccess file with the following content:



AddDefaultCharset UTF-8

AddCharset UTF-8 .py
AddCharset UTF-8 .c


Only the first line wasn't enough in my case.


Answer



If you are allowed to place a .htaccess file in your content directory, you might be able to specify a charset there.



YMMV depending on which server software they run, and how permissive the config is.




See:



How to change the default encoding to UTF-8 for Apache?



htaccess UTF-8 encoding for .html, .css, .js - Whats the best way?


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...