Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent FF close websocket connection on ESC

There is know bug where Firefox closes the open websocket connection when the user presses ESC button. Is there a workaround or small jQuery code that can help me to prevent that? I was thinking to start a new websocket connection every time the current connection is being closed, but that seems a little dangerous.

like image 292
Bilgin Ibryam Avatar asked Aug 05 '12 12:08

Bilgin Ibryam


1 Answers

Have a look at https://bugzilla.mozilla.org/show_bug.cgi?id=676881 where this problem and a partial fix is discussed. The following snippet executed after the page is loaded works for me:

$(window).keydown(function(event) {
    // check for escape key
    if (event.which == 27) {
        // the following seems to fix the symptom but only in case the document has the focus
        event.preventDefault();
    }
});
like image 106
chessweb Avatar answered Nov 15 '22 11:11

chessweb