I have an iframe ( id: 'chat' ) with designMode='on' in Chrome.
On Enter a keypress event. I call the send() function, which takes the contents of the iframe and writes it to the socket. My problem is that when I clean the iframe, I lose focus.
How to adjust focus so that I can continue to enter text in an iframe?
function send(){ var $iframe = $('#chat'); var text = $iframe.contents().text() + "\n"; socket.send(text); // When this is done, the focus is lost // If commented, the focus will not be lost $iframe.contents().find('body').empty(); // My different failed attempts to regain the focus //$iframe.focus(); //$iframe.contents().focus(); //$iframe.contents().find('body').focus(); //$iframe.contents().find('body').parent().focus(); //$iframe[0].contentWindow.focus(); // I've also tried all the above with timers //setTimeout( function(){ $('
I have tried many solutions on other issues, but nobody is working.
source share