Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.execCommand() FontSize in pixels?

Tags:

How can I change font size to 30px (for example) using document.execCommand?

This:

document.execCommand("fontSize", false, "30px");

doesn't work, because in 3rd argument of the function execCommand, it only allows me to input a value between and including 1 to 7.

like image 758
bordeux Avatar asked May 03 '11 10:05

bordeux


1 Answers

It's a limitation of the FontSize command. There are various options I can think of:

  • You could use a CSS class instead and use the CSS class applier module of my Rangy library;
  • You could use a hacky method, such as calling document.execCommand("fontSize", false, "7"); and then finding the elements the command has created and changing them as required. See example: http://jsfiddle.net/S3ctN/. This obviously depends on there being no other <font> elements with size 7 in the document and it also relies on the browser using <font> elements for font size, which it seems they all do.
like image 121
Tim Down Avatar answered Oct 08 '22 00:10

Tim Down