A couple of very short but useful bits of Javascript

Javascript to branch on ESC

/* window-home.js */
/* - - - - - - - - - - - - - - - - - - - - - - - - */
/* ©1999-2024 W. Dwyne */

/* jshint curly: true */
/* jshint esversion: 6 */
/* jshint latedef: true */
/* jshint maxerr:10  */
/* jshint trailingcomma: true */
/* jshint nonew: true */
/* jshint undef: true */
/* jshint unused: true */

/* Back to home page when ESC is pressed. Simple script, took time to make it simple! */
/* Note: keydown at times requires two clicks, keyup solves the keydown problem */

/* Needs a link with an ID of home ie a id="home" href="index.htm" /a */


/*                        HTML required code example */
/* (Note: Fix - Mistakes are intentional to disable script in comment and PRE*/
/*   script src="java/window-home.js">/script>
/* head> */
/* body> */
/* a id="home"
/*   href="index.htm" */
/*   title="Home Page">🏠 Home */ /*  Return to Home Page  */

/* alert("window-home is active!"); */

document.addEventListener('keyup', event =>
  {
    if (event.key == 'Escape') {
      document.getElementById("home").click();
    }
  }
);
/* End */

Javascript to close window

/* window-close.js */
/* - - - - - - - - - - - - - - - - - - - - - - - - */
/* ©1999-2024 W. Dwyne */

/* jshint curly: true */
/* jshint esversion: 6 */
/* jshint latedef: true */
/* jshint maxerr:10  */
/* jshint trailingcomma: true */
/* jshint nonew: true */
/* jshint undef: true */
/* jshint unused: true */

/* Close page when ESC is pressed. Simple but took time to make it simple! */
/* Not really of much use due to the following browser restrictions */
/*      Scripts may not close windows that were not opened by script. */
/*      This script will not close an online browser, but will close an offline browser*/
/*Note: keydown at times requires two clicks, keyup solves the keydown problem */

/*                        HTML required code example */
/* (Note: Fix - Mistakes are intentional to disable script in comment and PRE*/
/* script src="java/window-close.js">/script> 
/head */


/* alert("window-close is active!"); */

document.addEventListener('keyup', event =>
  {
    if (event.key == 'Escape') {
      window.open("", "_self");
      window.close();

    }
  }
);
/* End */