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!
Does this work in your IE browser?
Moderator: General Moderators
-
condoravenue1
- Forum Commoner
- Posts: 30
- Joined: Fri Dec 03, 2010 10:24 pm
Re: Does this work in your IE browser?
Google is your friend: http://internet-explorer-for-mac.en.softonic.com/mac
-
condoravenue1
- Forum Commoner
- Posts: 30
- Joined: Fri Dec 03, 2010 10:24 pm
Re: Does this work in your IE browser?
Isn't that an old outdated browser?
I downloaded it once and used it. I have a hard time trusting it.
I downloaded it once and used it. I have a hard time trusting it.