Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/11/2006, 05:01
Avatar de dogduck
dogduck
 
Fecha de Ingreso: enero-2006
Ubicación: ¿Atlantida, Hesperides, Islas afortunadas?
Mensajes: 2.231
Antigüedad: 18 años, 4 meses
Puntos: 19
Java no es JavaScript, pero si te vale este código que he visto:
http://www.php-hispano.net/foros/Javascript/13408
Código HTML:
<html>
<head>
<title>Editor bbcode</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function instag(tag){
var input = document.form1.texto;
//para mac
if(typeof document.selection != 'undefined' && document.selection) {
var str = document.selection.createRange().text;
input.focus();
var sel = document.selection.createRange();
sel.text = "[" + tag + "]" + str + "[/" +tag+ "]";
return;
}else if(typeof input.selectionStart != 'undefined'){
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + '['+tag+']' + insText + '[/'+tag+']'+ input.value.substr(end);
return;
}else{
  input.value+=' ['+tag+']Reemplace este texto[/'+tag+']';
  return;
}
}
</script>
<script>
function inslink(){
var input = document.form1.texto;
if(typeof document.selection != 'undefined' && document.selection) {
var str = document.selection.createRange().text;
  input.focus();
  var my_link = prompt("Enter URL:","http://");
  if (my_link != null) {
    var sel = document.selection.createRange();
    sel.text = "[a href=\"" + my_link + "\"]" + str + "[/a]";
  }
  return;
}else if(typeof input.selectionStart != 'undefined'){
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
var my_link = prompt("Enter URL:","http://");
if (my_link != null) {
input.value = input.value.substr(0, start) +"[a href=\"" + my_link + "\"]" + insText  + "[/a]"+ input.value.substr(end);
}
return;
}else{
var my_link = prompt("Ingresar URL:","http://");
var my_text = prompt("Ingresar el texto del link:","");
input.value+=" [a href=\"" + my_link + "\"]" + my_text + "[/a]";
return;
}
}
</script>
</head>

<body>
<form name="form1" method="post" action="">
<input type="button" name="Submit" value="B" onclick="instag('b')">
  <input type="button" name="Submit3" value="U" onclick="instag('u')">
<input type="button" name="Submit4" value=" I " onclick="instag('i')">
  <input type="button" name="Submit2" value="LINK" onclick="inslink()">
  <br>
  <textarea name="texto" cols="40" rows="10" id="texto"></textarea>
  
</form>
</body>
</html>