Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #33001 > unrolled thread

Is there a way to send Escape keyCode to close whatever popup on the screen?

Started byjustaguy <lichunshen84@gmail.com>
First post2017-04-13 20:26 -0700
Last post2017-04-16 18:09 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  Is there a way to send Escape keyCode to close whatever popup on the screen? justaguy <lichunshen84@gmail.com> - 2017-04-13 20:26 -0700
    Re: Is there a way to send Escape keyCode to close whatever popup on the screen? JJ <jj4public@vfemail.net> - 2017-04-14 12:23 +0700
      Re: Is there a way to send Escape keyCode to close whatever popup on the screen? justaguy <lichunshen84@gmail.com> - 2017-04-16 18:09 -0700

#33001 — Is there a way to send Escape keyCode to close whatever popup on the screen?

Fromjustaguy <lichunshen84@gmail.com>
Date2017-04-13 20:26 -0700
SubjectIs there a way to send Escape keyCode to close whatever popup on the screen?
Message-ID<7cd34ecf-0cea-4e1b-845c-2be259210348@googlegroups.com>
Hi,

Some times we see some pop up screen and if we press the Esc key the pop up screen would disappear (close).  
I wonder if we are able to send some js code to execute the manual Esc key press, that is, how to send the keyCode of 27 to the browser via JS?

Thanks.

[toc] | [next] | [standalone]


#33002

FromJJ <jj4public@vfemail.net>
Date2017-04-14 12:23 +0700
Message-ID<1jx41mkaa83x5.1e2giv8ezp05y$.dlg@40tude.net>
In reply to#33001
On Thu, 13 Apr 2017 20:26:53 -0700 (PDT), justaguy wrote:
> Hi,
> 
> Some times we see some pop up screen and if we press the Esc key the pop
> up screen would disappear (close). I wonder if we are able to send some
> js code to execute the manual Esc key press, that is, how to send the
> keyCode of 27 to the browser via JS?
> 
> Thanks.

You can generate a keyboard event by creating the keyboard event, populate
the event object with the correct property values e.g. key code, key
character, key name, etc., then dispatch the event to the DOM object which
has a keyboard event listener that accept the ESCAPE key to close the popup.

Keyboard event listener that does as such is likely attached to the `window`
object, but it can be on the `document` object, the `BODY` element, popup
HTML element, etc. You'll have to experiment if you don't know where the
keyboard event listener is attached to.

Since the ESCAPE key can generate `keypress`, `keydown`, and `keyup` events,
if you don't know which one is used for the popup's keyboard event listener,
you'll have to experiment this too.

If you know the popup's keyboard event listener code and which function it
calls to close the popup, it's more easier to simply call that function, or
if it's not accessible (e.g. due to private function), create a function
that do the same task.

[toc] | [prev] | [next] | [standalone]


#33025

Fromjustaguy <lichunshen84@gmail.com>
Date2017-04-16 18:09 -0700
Message-ID<8a3270d8-fa4e-4c31-b388-7ac778af7340@googlegroups.com>
In reply to#33002
On Friday, April 14, 2017 at 1:23:58 AM UTC-4, JJ wrote:
> On Thu, 13 Apr 2017 20:26:53 -0700 (PDT), justaguy wrote:
> > Hi,
> > 
> > Some times we see some pop up screen and if we press the Esc key the pop
> > up screen would disappear (close). I wonder if we are able to send some
> > js code to execute the manual Esc key press, that is, how to send the
> > keyCode of 27 to the browser via JS?
> > 
> > Thanks.
> 
> You can generate a keyboard event by creating the keyboard event, populate
> the event object with the correct property values e.g. key code, key
> character, key name, etc., then dispatch the event to the DOM object which
> has a keyboard event listener that accept the ESCAPE key to close the popup.
> 
> Keyboard event listener that does as such is likely attached to the `window`
> object, but it can be on the `document` object, the `BODY` element, popup
> HTML element, etc. You'll have to experiment if you don't know where the
> keyboard event listener is attached to.
> 
> Since the ESCAPE key can generate `keypress`, `keydown`, and `keyup` events,
> if you don't know which one is used for the popup's keyboard event listener,
> you'll have to experiment this too.
> 
> If you know the popup's keyboard event listener code and which function it
> calls to close the popup, it's more easier to simply call that function, or
> if it's not accessible (e.g. due to private function), create a function
> that do the same task.

My initial thought is to see if there some "sequences" of javascript statements to execute the ESC key depress function, Not some event triggered.  Now the problem has been solved, so, no need for this solution.
Thanks tho.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web