execCommand setting css class in a WYSIWYG editor

A

Andrew Crowe

Hi,

I've been trying to edit an inbrowser WYSIWYG editor that relies on
execCommand for most of its operations.

I would like a dropdown of styles that a user can choose and are applied
to the outer tag of their current selection.

I've created the following by editing an example I found online but it
only works in IE:


function SelectClass(selectname) {
if (selectname.selectedIndex != 0) {
option=selectname.options[selectname.selectedIndex].value;
selectname.selectedIndex = 0;

if (browser.isIE5up) {
sel = EpozElement.contentWindow.document.selection;
range = sel.createRange();
el = range.parentElement();
}else{
sel = EpozElement.contentWindow.window.getSelection();
range = sel.getRangeAt(0);
el = range.parentNode;
}

if (option != 'none') {
el.className = option;
}
if (option == 'none') {
el.removeAttribute('className');
}

EpozElement.contentWindow.focus();
}
}




I've tried a few things but I can't work out what the Mozilla equivalent
to range.parentElement() is.

If anyone can see how I can get that to work in Mozilla, or knows of a
way to do this using execCommand then that'd be much appriciated


Thanks
Andrew
 
J

Jan Clemens Faerber

Andrew said:
I've tried a few things but I can't work out what the Mozilla equivalent
to range.parentElement() is.

try this:

} else if (browser == "Mozilla") {
sel = EpozElement.contentWindow.window.getSelection();
el = sel.anchorNode;
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top