Scusate per il flood continuo... sto cercando in tutti i modi di adattarlo...
codice:
function getSelText() {
txt = '';
if (window.getSelection) {
txt = window.getSelection();
} else if (document.getSelection) {
txt = document.getSelection();
} else if (document.selection) {
txt = document.selection.createRange().text;
} else return
}
function add_g() {
var obj=document.form_note.note;
if (txt == '') {
text = prompt("Inserisci la parola o frase che desideri in grassetto...");
} else {
text = prompt("Inserisci la parola o frase che desideri in grassetto...", txt);
}
if (document.all) {
obj.focus();
var sel=document.selection;
var rng=sel.createRange();
rng.colapse;
rng.text=""+ text +"";
} else if(obj.selectionEnd){
var lng=obj.textLength;
var from=obj.selectionStart;
var to=obj.selectionEnd;
obj.value=obj.value.substring(0,from) + ""+ text +"" + obj.value.substring(to,lng)
} else {
obj.value+=""+ text +"";
}
obj.focus();
}
In pratica se il testo è selezionato non aprirmi il prompt ma usa il testo selezionato, se invece non è selezionato niente aprimi il prompt affinchè l'utente scriva la frase desiderata.