Page 1 of 1

Does this work in your IE browser?

Posted: Tue Aug 23, 2011 12:15 pm
by condoravenue1
On my site (bible-help.com) I want to allow users to comment. When they click the 'bold' button, I want <b> and </b> to appear around the selected text (similar to this forum). Here is the code I have that works for Chrome, Firefox, and Safari. I can't tell if it works on IE cause I use a mac.

function formatText(el, tag)
{
if (el.setSelectionRange)
{
el.value = el.value.substring(0,el.selectionStart) + "<" + tag + ">" + el.value.substring(el.selectionStart,el.selectionEnd) + "</" + tag + ">" + el.value.substring(el.selectionEnd,el.value.length)
}
}

Does this work in IE?

If it doesn't I saw this code somewhere:

function formatText(tag)
{
var selectedText = document.selection.createRange().text;
var newText = "<" + tag + ">" + selectedText + "</" + tag + ">";
document.selection.createRange().text = newText;
}

Will that work in IE?

Currently on my site I have the two combined, but I don't know if it works:

function formatText(el, tag)
{
if (el.setSelectionRange) {
el.value = el.value.substring(0,el.selectionStart) + "<" + tag + ">" + el.value.substring(el.selectionStart,el.selectionEnd) + "</" + tag + ">" + el.value.substring(el.selectionEnd,el.value.length)
}
else {
var selectedText = document.selection.createRange().text;
var newText = "<" + tag + ">" + selectedText + "</" + tag + ">";
document.selection.createRange().text = newText;
}
}

Thanks for your help!

Re: Does this work in your IE browser?

Posted: Fri Aug 26, 2011 9:44 am
by Jade

Re: Does this work in your IE browser?

Posted: Fri Aug 26, 2011 11:45 am
by condoravenue1
Isn't that an old outdated browser?

I downloaded it once and used it. I have a hard time trusting it.