-2

My web page uses bootstrap and jquery, and during a rather long page load, which reads some PHP session variables with JSON_ENCODE, pressing the ESCAPE key seems to stop the process, aborting the read, and causing the page load to fail.

This occurs in both Chrome and Firefox.

What could be causing this, and is there any way to prevent this?

Thank you.

EDIT *(added the ignore_user_abort but ESCAPE still aborts):

<?php ignore_user_abort(true); ?>
var db = <?php echo (isset($_SESSION["data"])) ? 
  json_encode($_SESSION["data"], JSON_PRETTY_PRINT) : 0 ; ?>;
if (!db) db = {};
iSofia
  • 1,412
  • 2
  • 19
  • 36
  • http://php.net/manual/en/features.connection-handling.php – CBroe Jan 29 '18 at 14:38
  • Thank you @CBroe. I'm quite an amateur at this and hadn't realized that the connection could be aborted. Still, I added that (please see code edit) but it didn't prevent the abort. – iSofia Jan 29 '18 at 15:36

1 Answers1

1

I got the solution to control the " F5 , Esc , BackSpace(BS) " keys with the following code.

My Java Script code will be ,

document.attachEvent("onkeydown", win_onkeydown_handler);

function win_onkeydown_handler() {
    switch (event.keyCode) {

    case 116 : // 'F5'
         event.returnValue = false;
         event.keyCode = 0;
         break;  

    case 27: // 'Esc'
        event.returnValue = false;
        event.keyCode = 0;
        break;

    case 08: // 'BackSpace'
        if (event.srcElement.tagName == "INPUT"
                || event.srcElement.tagName == "TEXTAREA") {
        } else {
            event.returnValue = false;
            event.keyCode = 0;
        }
        break;

    }
}

Thanks who are all supported me to do this and for your suggestions.

https://stackoverflow.com/a/14603299/8939708

The issue is that ESC key stops the browser from loading the page. Hence the page crashes, i don't know if this answer would help you or not. If it doesn't feel free to comment and i'll delete it. Hope i helped.

Farhan Qasim
  • 990
  • 5
  • 18
  • Thank you Farhan. Your solution works (with addEventListener). I'd much prefer a PHP solution, as CBroe had pointed out, but I'll mark this as the answer if I don't get anything else. Thanks again. – iSofia Jan 29 '18 at 15:42
  • No problem, it would be great if you could upvote the answer given in the link, as the credit goes to him not me. You're welcome. – Farhan Qasim Jan 29 '18 at 15:43