2010-08-19 8 views
5

Quando ho incollare qualsiasi testo in qualsiasi elemento con 'contentEditable' bandiera abilitato, IE rileva automaticamente i collegamenti ipertestuali o indirizzi e-mail e li sostituisce condisabilitare il rilevamento automatico di URL per elementi con la bandiera 'contentEditable' in IE

<a href="hyperlink">hyperlink</a>. 

Come posso disabilitare questo rilevamento automatico dell'URL per elementi (es. Div, span ecc.) Con flag "contentEditable" in IE o aleast ottenere il testo reale che è stato incollato nel div.

migliori saluti,
Keshav

risposta

1

Io non credo che si possa. Avrai bisogno di prendere l'evento paste e impostare un breve timer che chiama una funzione che rimuove i collegamenti.

Modifica 30 settembre 2012

IE 9 e soprattutto ha la capacità di cambiare questa via. Guarda la risposta di Maxon.

3

Sfortunatamente, non esiste una soluzione per versioni incrociate. In IE9 v'è la possibilità, che permette di disattivare il collegamento ipertestuale automatico:

document.execCommand("AutoUrlDetect", false, false); 

Maggiori informazioni: http://msdn.microsoft.com, http://bytes.com

+2

Questo non sembra funzionare su IE11 – jreptak

+0

Confermato di non funzionare in IE11 – Artif3x

0

Io uso preventDefault sulla barra spaziatrice, tasto Invio, evento KeyDown del tasto tab per impedire il rilevamento URL. Testato su IE11 e Chrome.

document.getElementById("input").addEventListener("keydown", function (e) { 
    var SPACEKEY = 32; 
    var ENTERKEY = 13; 
    var TABKEY = 9; 

    var whiteSpace = ""; 

    if (e.keyCode == SPACEKEY || e.keyCode == ENTERKEY || e.keyCode == TABKEY) { 
    e.preventDefault(); 

    if (e.keyCode == SPACEKEY) { 
     whiteSpace = " "; 
    } else if (e.keyCode == ENTERKEY) { 
     whiteSpace = "\n"; 
    } else if (e.keyCode == TABKEY) { 
     whiteSpace = "\t"; 
    } 

    var selection = document.getSelection(); 
    var start = selection.anchorOffset > selection.focusOffset ? selection.focusOffset : selection.anchorOffset; 
    var end = selection.anchorOffset > selection.focusOffset ? selection.anchorOffset : selection.focusOffset; 

    $(this).text($(this).text().substring(0, start) 
     + " " 
     + $(this).text().substring(end)); 
    var range = document.createRange(); 
    range.setStart($(this)[0].firstChild, start + 1); 
    range.setEnd($(this)[0].firstChild, start + 1); 
    selection.removeAllRanges(); 
    selection.addRange(range); 
    } 
    return false; 
}); 
Problemi correlati