2

all.. I do know that this question is kind of scattered over the internet, but nothing seems to be pointing me right.

I am making my own wysiwyg and the problem I'm facing is that the code

document.execCommand("fontSize", false, value);

accepts only values from 1 to 7 (inclusive) to be assigned to the "size" attribute of "font" tag. However I need to set the font-size in pixels.

I found this example in a similar stackoverflow question. But the problem with this approach is that it only changes the font-size for the selected text. if you aim to set the font-size before typing your text, it will not work.

Does any one have any idea how I can solve this?

Community
  • 1
  • 1
soroush
  • 23
  • 2
  • 6

1 Answers1

1

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 elements with size 7 in the document and it also relies on the browser using elements for font size, which it seems they all do

document.execCommand() FontSize in pixels?

Community
  • 1
  • 1
K008
  • 11
  • 2