How do I know which font has been used in Web page?
/**
* Get the font used for a given element
* @argument {HTMLElement} the element to check font for
* @returns {string} The name of the used font or null if font could not be detected
*/
function getFontForElement(ele) {
if (ele.currentStyle) { // sort of, but not really, works in IE
return ele.currentStyle["fontFamily"];
} else if (document.defaultView) { // works in Opera and FF
return document.defaultView.getComputedStyle(ele,null).getPropertyValue("font-family");
} else {
return null;
}
}
#fonttester {
font-family: sans-serif, arial, helvetica;
}
Tags: html javascript css fonts
Source: By Pat as answer to the question
This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 4.0
Related code-snippets:
- Why did the width collapse in the percentage width child element in Internet Explorer 7?
- Which timezone is most important?
- Multiple submit buttons in HTML form.
- How can I print an HTML document from a web service?
- How can I find the full path of a font from its display name on a Mac?
- How to break word after special character like Hyphens (-)?
- ASP.Net Custom Client-Side Validation. ASP.Net has created thousands of Web Application Test cases.
- What do I do with triple quotes? How do I delimit a databound Javascript string parameter in ASP.NET?
- How do I make a checkbox toggle from clicking on the text label as well?
- How do you disable browser autocomplete on web form field?
- What are some examples of options for HTML scraping?
- How do I make the browser see CSS and JavaScript changes?
- How do I set the background color of HTML element using CSS properties in JavaScript?
- How do I capture TAB key in text box?
- How do I call ASP.NET functions from JavaScript?