javascript - Change Arial to some other font on the whole webpage -


i'm thinking script can change webpage's font appearance arial other font face of choice.

how should go doing that?

i understand: * { font-family: "somefont"; }

but won't achieve objective target arial text.

i can use jquery or javascript, whichever more efficient , fast.

edit: seems people have difficulty understanding question. i'll explain more, want arial text on webpage, if exists, change in appearance.

i going suggest looping through stylesheets array and, each style sheet, loop through rules, find ones defining arial font, , change other font want. way wouldn't have visit every element on page.

the problem suggestion, though, inline styles on elements.

so hate say, you'll have visit every element on page. pages, won't problem, mileage may vary.

here's how you'd jquery:

$("*").each(function() {     var $this = $(this);     if ($this.css("font-family").tolowercase().indexof("arial") !== -1) {         $this.css("font-family", "someotherfont");     } }); 

can't it, though. :-) can avoid building massive list ($("*") builds jquery object containing all of page elements, can quite large) @ outset if recursive walk instead, e.g.:

$(document.body).children().each(updatefont); function updatefont() {     var $this = $(this);     if ($this.css("font-family").tolowercase().indexof("arial") !== -1) {         $this.css("font-family", "someotherfont");     }     $this.children().each(updatefont); } 

that may preferable, you'd have profile it.

doing without jquery involve recursively looping through childnodes of each element , using either getcomputedstyle (most browsers) or currentstyle (ie) font information, (if necessary) assigning element.style.fontfamily.


actually, "both and" solution best. first, update stylesheets, , walk tree catch inline styles. way, presumably you'll of them changing stylesheets, avoid ugliness of piecemeal update. also, don't have use css() (jquery) or getcomputedstyle / currentstyle (without jquery), can check element.style.fontfamily, more efficient.

beware ie's stylesheet object uses array called rules, others use cssrules, other largely same.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -