Re: Using Javascript to Detect Script Support in a Browser

From: Christoph Päper (christoph.paeper@crissov.de)
Date: Thu Jun 17 2010 - 03:39:00 CDT

  • Next message: Doug Ewell: "Re: Using Javascript to Detect Script Support in a Browser"

    Ed Trager:
    > On Tue, Jun 15, 2010 at 5:52 PM, Marc Durdin
    >>
    >> P { font-family: Code2000, MyCode2000; }
    >> @font-face { font-family: MyCode2000; src: url('code2000.ttf'); }
    >>
    >> P { font-family: MyCode2000; }
    >> @font-face { font-family: MyCode2000; src: local("Code2000"), url('code2000.ttf'); }
    >
    > (…) I want my Javascript to know definitively whether the user agent has a font for rendering scripts that are less common (…).

    You (or your script) shouldn’t have to know. Describe the font files you provide, remember to use ‘unicode-range’, and let browsers figure out whether they need to download them.

    > If I only needed to check just a few scripts, letting the user agent do it all via statically-defined CSS rules as you have above would be enough. But in my case I may need to check more than just a few scripts, and so I want to use Javascript to set up additional @font-face rules dynamically on an as-needed basis.

    I don’t understand. You still have to decide which font(s) should be downloaded for which script (or rather code range) anyway.

    Or is your problem that you would do something like this:

      font-family: "font that is known to support this script
                    and may be installed locally",
                   "my virtual font-face comprised of downloads
                    and perhaps local files";

    and are concerned that there could be a "locally installed font that supports this script, but I didn’t know about" which would then be ignored in favor of the virtual font, resulting in an unnecessary download?

    If I’m not mistaken it should work, in theory at least, to put a generic font family (i.e. ‘serif’, ‘sans-serif’ etc.) _before_ your virtual font in the ‘font-family’ declaration. Many user agents can be set up to use a specific font per script (or codepage) for each generic family (or all of them), although the less common or new ones probably are lumped together as ‘Unicode’ or something similar. Browsers probbly wouldn’t probe all local (sans) serif fonts before trying the next option in the font list the CSS author provided.

      font-family: Code2000, serif, MyCode2000;

    PS: Is this CSS discussion on topic for this list?



    This archive was generated by hypermail 2.1.5 : Thu Jun 17 2010 - 03:42:43 CDT