Results 1 to 4 of 4

Thread: How to Close Pop up by pressing ESC Key

  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile How to Close Pop up by pressing ESC Key

    Hi,

    Please tell me.

    in my application i opened some popups.
    to close that popups wrote script window.top.close to close button.
    ok it is working

    but i want to Close Pop up when i pressing ESC Key.

    no mouse actions only keybord esc key.

    how can i do it. please tell me anybody knows.

    Thanks,

  2. #2
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Put this in the popup. It should work.
    Code:
    <script type="text/javascript">
    	window.onkeyup = function (event) {
    		if (event.keyCode == 27) {
    			window.close ();
    		}
    	}
    </script>

  3. #3
    Join Date
    Jan 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    can you pl. tell me where to put this script? in <head> or <body>

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You shouldn't co-opt the Esc key to do anything. It already has functions in several browsers.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •