Chrome にiframe ( id: 'chat'
) があります。designMode='on'
Enter keypress イベントでsend()
、 iframe の内容を取得してソケットに書き込む function を呼び出します。私の問題は、iframe をクリアすると、フォーカスが失われることです。
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(){ $('#chat').contents().focus(); }, 100);
}
他の質問に対して多くの解決策を試しましたが、どれもうまくいかないようです。