To replace ':)' to image I see 2 variants: When I detect ':)' I: 1. Emulate two BackSpace and execCommand('InsertImage',false,img) 2. Get all text from '#editor', then String.replace(/:\)/g,img), then put that in '#editor', then need moove cursor to the end of '#editor'. I dont know how to move cursor to the end of editor.
I select 1st variant, and try emulate BackSpace key. Using $ ('#editor').trigger("keypress", ........) I cant do this - I dont ckow how! I find: var evt = document.createEvent("KeyEvents"); evt.initKeyEvent( "keypress", // in DOMString typeArg, true, // in boolean canBubbleArg, true, // in boolean cancelableArg, null, // in nsIDOMAbstractView viewArg, Specifies UIEvent.view. This value may be null. false, // in boolean ctrlKeyArg, false, // in boolean altKeyArg, false, // in boolean shiftKeyArg, false, // in boolean metaKeyArg, 8, // in unsigned long keyCodeArg, 0); // in unsigned long charCodeArg); $('#editor')[0].dispatchEvent(evt); it's work in FF, but dont work in IE. > Ah, I think I see the issue. Am I right in assuming that you don't > want to simulate the backspace, but detect it? I need to simulate the BackSpace > Also, how are you keeping track of the replacement? It seems to me > that you could do yourself a big favor and make what the user enters > not what you show the user, so when they delete a smiley, you can just > remove the whole thing?