![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
26/01/2008, 13:35
|
![Avatar de Panino5001](http://static.forosdelweb.com/customavatars/avatar65984_5.gif) | Me alejo de Omelas | | Fecha de Ingreso: mayo-2004 Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años, 8 meses Puntos: 834 | |
Re: borrar enlace Más o menos así:
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<script>
campo='ejemplo';
function quitarenlace(){
var input = document.getElementById(campo);
var patern= /^\s*<a\b[^>]*>(.*?)<\/a>\s*$/;
if(typeof document.selection != 'undefined' && document.selection) {
var str = document.selection.createRange().text;
input.focus();
var sel = document.selection.createRange();
if(!patern.test(sel.text)){throw 'error al seleccionar el enlace';return;}
sel.text = sel.text.split('>')[1].split('<')[0];
sel.select();
return;
}else if(typeof input.selectionStart != 'undefined'){
if(typeof input.scrollTop != 'undefined'){
var st=input.scrollTop;
var sl=input.scrollTop;
}
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
if(!patern.test(insText)){throw 'error al seleccionar el enlace';return;}
insText=insText.split('>')[1].split('<')[0];;
input.value = input.value.substr(0, start) +insText+ input.value.substr(end);
input.focus();
if(typeof input.scrollTop != 'undefined'){
input.scrollTop=st;
input.scrollTop=sl;
}
return;
}else{
return;
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<textarea name="ejemplo" cols="60" rows="5" id="ejemplo">otra cosa <a href="http://www.google.com">lo que sea </a> otra cosaotra cosa <a href="http://www.google.com">lo que sea </a> otra cosa</textarea>
<input type="button" name="Submit" value="quitar enlace" onclick="try{quitarenlace();}catch(e){alert(e)}" />
</form>
</body>
</html>
|