Does this work in your IE browser?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
condoravenue1
Forum Commoner
Posts: 30
Joined: Fri Dec 03, 2010 10:24 pm

Does this work in your IE browser?

Post 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!
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Does this work in your IE browser?

Post by Jade »

condoravenue1
Forum Commoner
Posts: 30
Joined: Fri Dec 03, 2010 10:24 pm

Re: Does this work in your IE browser?

Post by condoravenue1 »

Isn't that an old outdated browser?

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