Link i textarea
Jeg har dette script i en fil. Den skulle indsætte der hvor cursoren er, men det gør den ikke.<script language="JavaScript">
function GemPos (textEl) {
if (textEl.createTextRange)
textEl.caretPos = document.selection.createRange().duplicate();
}
function IndsetVedPos (textEl, text) {
if (textEl.createTextRange && textEl.caretPos) {
var caretPos = textEl.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}else{
textEl.value = textEl.value + text;
}
return true;
}
function Kommando(which, action) {
var revisedMessage;
var currentMessage = document.test.content.value;
if (action == "test1") {
IndsetVedPos(document.test.content, "TEST1");
document.test.content.focus();
return;
}
if (action == "test2") {
IndsetVedPos(document.test.content, "TEST2");
document.test.content.focus();
return;
}
if (action == "link") {
lnk = prompt("Indtast link (url)","http://")
txt = prompt("Indtast tekst til link","Indtast her")
IndsetVedPos(document.test.content, "<a href=" + lnk + ">" + txt + "</a>");
document.test.content.focus();
return;
}
}
</script>
Hvad er der galt?
