/    Sign up×
Community /Pin to ProfileBookmark

FontSize ExecCommand

Hello Javascripters! I am new to this forum but I have something which
keeps my mind buggin.. If you change FontSize in javascript by a fairly simple command:
‘ActiveDocument.execCommand “fontsize”, False, “7”‘
everything works great but the code created in each browser is slightly diffrent even if CSS is standard enabled.

Firefox
<font size=”7″>text</font>
(is deprecated no?)

Chrome
<span class=”Apple-style-span” style=”font-size: -webkit-xxx-large;”>text</span>

So here is my question how can I get in all browsers something like?
<span style=”font-size: 24px;”>Text</span>
I have notitced yahoo editor works like that but I can’t figure out where the hot potato is.
[url]http://developer.yahoo.com/yui/examples/editor/simple_adv_editor.html[/url]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangJun 05.2010 — Use:document.body.style.fontSize = '24px';
Copy linkTweet thisAlerts:
@PixelDudeauthorJun 05.2010 — Thanks Fang! of moet ik zeggen bedankt! ?

I was already working on something like below for the wysiwyg editor


function fontChange(value)

{


selection = Editor.window.getSelection();


range = Editor.window.getSelection().getRangeAt(0);

repl = Editor.document.createTextNode(range);

var span = Editor.document.createElement("span");

span.style.fontSize = value;

range.deleteContents(); span.appendChild(repl); range.insertNode(span);

}


Now I still have to figure out a way to see if a parent <span> element exists and if the fontsize is the same..

otherwise I will create 100x <span> by every change the user makes..

p.s. code is not explorer safe yet, but then again WHO uses explorer these days! (kidding)
×

Success!

Help @PixelDude spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...