In an HTML link to a text file, how to specify the charset of the file?

I have a web page with a link (anchor tag) to a text file that is in UTF-8 format. Linking to it from Safari on my Mac (Catalina) it looks fine, but linking to it from Safari on my iPhone does not display the non-ASCII characters correctly. In my HTML anchor (A) tag, how do I specify that the target file is UTF-8 so that Safari on my iPhone will display it correctly? ―Ken Nellis

iPhone SE, iOS 14

Posted on Apr 16, 2021 12:42 PM

Reply

Similar questions

10 replies

Apr 17, 2021 10:21 AM in response to Ken Nellis

Ken Nellis wrote:

Could the respective sites themselves be providing charset hints to Safari?

I have not run into it for a long time, but the default of some web servers used to be to tell browsers to use Latin 1 encoding (regardless of what the page code may have stipulated). The fix was to modify some server setting. You might have a look at that. Do you see the same problem if you put a self-composed text with a bunch of utf8 accented characters in it on your server?

Apr 16, 2021 1:53 PM in response to Ken Nellis

Apparently, why it works on my Mac is because I have Safari > Preferences > Advanced > Default encoding: Unicode (UTF-8). When I change it to Western (ISO Latin 1) it renders the file as does my iPhone. On my iPhone I looked in Settings > Safari, but didn't see a corresponding setting. Regardless, it seems my HTML anchor tag should be able to specify the file's encoding. It also seems that the iPhone's Safari should have that setting.

―Ken

Apr 16, 2021 1:09 PM in response to Ken Nellis

Ken,


The HTML anchor allows you to specify a type, and for UTF-8 content, it would be the non-intuitive:


<a href="file:///Users/yourname/Desktop/exif.txt type="text/strings">exif.txt</a>


I have a text file on my Desktop that is a dump of EXIF data from an image. It makes no difference in its presentation on the web page whether I omit the anchor type clause above, and just let the <head> charset="UTF-8" control the display of the page.

Apr 17, 2021 8:59 AM in response to Tom Gewecke

Thanx, Tom, but the issue is how to coerce modifiable software correctly read an immutable file, in this case one that must remain an exact duplicate of the one on the Unicode site. The mystery remains: why does Unicode's copy of the file render correctly in Safari, but my exact duplicate renders incorrectly. Could the respective sites themselves be providing charset hints to Safari? (My site uses Apache. I have no idea what the Unicode site uses.)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

In an HTML link to a text file, how to specify the charset of the file?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.