Pages

Wednesday, 18 July 2012

Apex - closing modal page on escape

I've been making use of the Skillbuilders Modal Page plug-in a fair bit recently, and I thought I'd share this little ditty on closing the dialog when the escape button is pressed.

I set the event to Key Release, using the 'document' DOM object.

The JavaScript condition is set to 'event.which = 27' - the ASCII translation of the escape key.

Finally, the true action closes the window, passing nothing back to the calling page
javascript:window.parent.$(window.parent.document).apex_modal_page('close','');>

Inline images 1

Of course, aside from the action - the same event can be captured if you're listening for the escape key for whatever reason.

Hope it helps.

2 comments:

  1. Hi Scott,

    Very nice. I'll consider adding this as a declarative option in the future.

    Regards,
    Dan

    ReplyDelete
  2. Cool - and thanks again for a very useful plug-in!

    ReplyDelete