I am currently working with a text editor that has the ability to use designMode
along with an <iframe>
. My goal is to change the font to a Google Web font. Below is the JavaScript code I am using:
function setFont(fontName, boolValue, fontText) {
editor.execCommand("styleWithCSS", true, null);
editor.execCommand(fontName, boolValue, fontText);
editor.focus();
}
This is the HTML for selecting fonts:
<select onchange="if (this.selectedIndex > 0) {setFont('fontName', false, this.options[this.selectedIndex].text);}">
<option selected>Font</option>
<option>Arial</option>
<option>Times New Roman</option>
<option>Courier</option>
<option>Consolas</option>
<option>Calibri</option>
<option>Molle</option>
</select>
Within the <iframe>
file, you will find this CSS link:
<link href='https://fonts.googleapis.com/css?family=Molle:400italic' rel='stylesheet' type='text/css'>
My attempt to change the font of the text through CSS includes:
span[style="font-family: Molle"] {
font-family: 'Molle', cursive;
}
Unfortunately, this solution does not work as intended. Keep in mind that it only needs to work in Google Chrome.