4

Sometimes people fill in forms with weird stuff like strange Unicode combinations in order to show special fonts.

For instance:

However, sometimes the characters are not supported by the client, and thus result in a "".

How can I detect the failure with JavaScript? Is this possible?

Thanks

AGamePlayer
  • 7,404
  • 19
  • 62
  • 119
  • Maybe a dupe of https://stackoverflow.com/questions/35609728/is-it-possible-to-detect-when-a-browser-is-using-a-fallback-font-instead-of-the? I'm not sure. –  Oct 04 '19 at 16:08
  • 2
    What do you mean by "supported with JavaScript"? The char you're showing is a char like any other; what do you want to do with it that you find impossible? – Mr Lister Oct 06 '19 at 19:26
  • @MrLister I want to know whether I can use pure JavaScript to detect this (without other technology like some client-side or OS-level stuff) – AGamePlayer Oct 07 '19 at 03:55

2 Answers2

0

The best way is to do it in the other way:

  • you select the webfont, and so the allowed ranges. Webfont description gives you the allowed character list, usually designers will enhance, and never remove glyphs.

  • you allow only such characters in your form.

Otherwise it will depend on the web browser. The same user could see different outcome if it is in different browser (e.g. mobile vs. computer). So the best way (IMHO) it is to remove client fonts altogether from the rendering, and so you explicitly specify the glyphs (and how to display it) by using a webfont. This is independent of client/webbrowser (but on very old ones)

Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32
-6

You can detect non-characters, that fulfills the use case given in the question.

use utf8;
use Unicode::UCD qw(charinfo);
if (defined charinfo ord '') {
    print 'is a character';
} else {
    print 'is a non-character';
}

See https://npmjs.com/search?q=ucd for JavaScript UCD libraries.

daxim
  • 39,270
  • 4
  • 65
  • 132
  • JS programmers: please edit the answer and substitute the code when you've found a good one. – daxim Oct 07 '19 at 07:10
  • 2
    OP's problem is pretty surely a font rendering problem, not a problem with the character as such. And a code sample for Perl (?) in a Javascript question is… odd… – deceze Oct 07 '19 at 07:30
  • 1
    Yeah, and regular characters sometimes *do not* render due to missing fonts. Which is more likely the problem for OP. – deceze Oct 07 '19 at 07:47
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/200500/discussion-on-answer-by-daxim-how-do-i-detect-if-a-character-like--is-a-un). – deceze Oct 07 '19 at 10:10