orhun
12-16-2009, 10:30 PM
i want to make an very very basic rich-text editor, which works in all browser types.
i have the code at below.. but it only works on -8 IE browsers.
could someone help me to make this code crossbrowser..
<script type="text/javascript">
<!--
function formatText (tag) {
var selectedText = document.selection.createRange().text;
if (selectedText != "") {
var newText = "[" + tag + "]" + selectedText + "[/" + tag + "]";
document.selection.createRange().text = newText;
}
}
//-->
</script>
<form name="my_form">
<textarea name="my_textarea"></textarea><br />
<input type="button" value="bold" onclick="formatText ('b');" />
<input type="button" value="italic" onclick="formatText ('i');" />
<input type="button" value="link" onclick="formatText ('link');" />
</form>
i have the code at below.. but it only works on -8 IE browsers.
could someone help me to make this code crossbrowser..
<script type="text/javascript">
<!--
function formatText (tag) {
var selectedText = document.selection.createRange().text;
if (selectedText != "") {
var newText = "[" + tag + "]" + selectedText + "[/" + tag + "]";
document.selection.createRange().text = newText;
}
}
//-->
</script>
<form name="my_form">
<textarea name="my_textarea"></textarea><br />
<input type="button" value="bold" onclick="formatText ('b');" />
<input type="button" value="italic" onclick="formatText ('i');" />
<input type="button" value="link" onclick="formatText ('link');" />
</form>