document.onkeypress = function esc(e) { 
 if(typeof(e) == "undefined") { e=event; }
 if (e.keyCode == 27) { parent.close(); }
}
