Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent default 'ctrl pageup' and 'ctrl pagedown' in Chrome
    primarykey
    data
    text
    <p>I have some code to create hotkeys for a web application. All of the hotkeys work in IE and Firefox, however <kbd>Ctrl</kbd>+<kbd>PgUp</kbd> and <kbd>Ctrl</kbd>+<kbd>PgDn</kbd> are not working in Chrome. </p> <p>After digging around for answers and writing some custom test code, I believe I have determined that this is because those events fire, in Chrome, on keyup instead of keydown. </p> <p>The default Chrome handlers for those events are firing instead of mine (or at least first) and switching the browser to the next or previous tab. If I use the hotkey to switch back to the tab with my application then my handlers catch the event.</p> <p>So my question is, is there any way to catch these events in Chrome and prevent the default functionality from running?</p> <p>The code in question is:</p> <pre><code> //These work in IE and Firefox $(this).bind('keydown', 'ctrl+pageup', (evt) =&gt; { this.prevPage(); return false; }); $(this).bind('keydown', 'ctrl+pagedown', (evt) =&gt; { this.nextPage(); return false; }); //These catch the event in chrome, but it's too late $(this).bind('keyup', 'ctrl+pageup', (evt) =&gt; { this.prevPage(); return false; }); $(this).bind('keyup', 'ctrl+pagedown', (evt) =&gt; { this.nextPage(); return false; }); </code></pre> <p>It does exactly what I want in IE and Firefox, but not Chrome. I have tried <code>evt.preventDefault()</code>, <code>evt.stopImmediatePropagation</code> and <code>evt.stopPropagation</code>. However, it does not work (I believe because my handlers are being called after the browser handlers).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload