Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keydown ESC capture function call

Status
Not open for further replies.

gorgered

Programmer
Dec 13, 2005
24
US
Hi,

I am using overlib.js lib to display the popups when clicked on a link. I am tyring to close the popup using ESC key.

The blow code works but when I tab over the link and hit enter key to open the popup I have to press ESC key twice.

Can I make it close by pressing ESC key only once?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript" src="overlib.js">
<!-- overLIB (c) Erik Bosrup -->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!--
addEvent(document,'keydown', closeInfo, false);

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

var Try = {
  these: function() {
    var returnValue;
	
    for (var i = 0; i < arguments.length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }
	
    return returnValue;
  }
}

function closeInfo(event){
 var e = event || window.event
 var characterCode = e.which || e.keyCode;
 if(characterCode == 27){
   return Try.these(
        function() {return nd();},
		function() {return nd();}
		);
 }
}

//-->
</SCRIPT>
</HEAD>

<BODY>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<a href="javascript:void(0);" onmouseover="return overlib('This is an ordinary popup.');" onmouseout="return nd();">here</a>
<BR>
<BR>
<BR>
<BR>
<a href="javascript:void(0);" onclick="return overlib('This is a sticky with a caption. And it is centered under the mouse!', STICKY, CAPTION, 'Sticky!', CENTER);" onmouseout="nd();">Click here!</a>
<BR>
  
</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top