3

Currently I have a lot of @font_face tags in my CSS

@font-face{
        font-family: Garamond;
        src: url('ePrintFonts/pcl_91545.ttf');
    }
    @font-face{
        font-family: CG Times;
        src: url('ePrintFonts/pcl_92500_CG.ttf');
    }
    @font-face{
        font-family: CG Omega;
        src: url('ePrintFonts/pcl_92506.ttf');
    }

I'm applying these font face tags using their font-family name to other elements. How can I access the src portion of the particular font with JavaScript if I'm given a particular element that has the font face applied to it?

2

1 Answer 1

0

Whilst both of the comments to your question provide links which show ways in which you can retrieve all applied rules for a given element, they cannot show you what is asked in the question.

I'm not sure there's a way of doing what you're asking using some simple JS. My (probably poor) suggestion would be to find something to parse the CSS file, and find it through that. It's worth noting however, that it's perfectly valid to have a rule such as:

src: local('Open Sans Bold'), local('OpenSans-Bold'), url('fonts/opensans-bold.woff') format('woff');

Whereby you first search for Local installations of the font and only use a URL if the user doesn't have them. For that reason this type of thing is even more complicated, and I've advise that you rethink your approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.