/    Sign up×
Community /Pin to ProfileBookmark

Avoiding browser actions

Hello,

I’m trying to write an editor in javascript.
I’m having a problem with a few keys:
– Backspace (goes back to previous page).
– Tab (moves focus).
– ‘ (opens the search bar in firefox).
– Arrows (move the window’s contents).

How can I block these keys from being processed by the browser as a shortcut to something.

Thank you.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorAug 04.2008 — By short: You [I]should not[/I] block them. Users expect their browsers to behavior as they were build for. You should rather define your own shortcuts, which must not interfere with the browsers' native shortcuts.
Copy linkTweet thisAlerts:
@slaughtersAug 04.2008 — Use the textarea input field:

A backspace inside a textarea field does not go to the previous page.

' does not open a search bar when typed in a textarea

Arrows do not move the windows contents in a textarea
Copy linkTweet thisAlerts:
@vesper8Aug 04.2008 — it's true you shouldn't block them, but if you wanted to you could. I have a website which does exactly that. You just need to listen for the keyboard input and add your own custom code when a specific key is pressed followed by a 'return false' which basically tells the browser not to do the default action for that button. I've been able to override most of buttons including F1, F2, F8, backspace, del etc. I haven't tried to do anything with tab. It was a pain to get it to work cross browser as you need to use different code for firefox and IE but in the end it works great. Albeit surely many developers would scold me for doing this ;p It is doable.
×

Success!

Help @the_dp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...