KeyUp from Javascript on Blackberry
Asked Answered
A

2

9

I am currently developing a web page designed for browsers and mobile devices and am having trouble with blackberry's

The functionality I want is to trigger a popup when a key is pressed. My current code works in browser, but not on the blackberry. I have javascript and javascript popups enabled on my blackberry emulator which is running OS 5.0.

The initial call:

 window.onkeyup = GetKeyUp;

And then the method:

 function GetKeyUp(e) {
        var KeyID = (window.event) ? event.keyCode : e.keyCode;
        alert(KeyID);
}

What is not working on Blackberry that would work in browser? Or alternatively:

How do I capture key presses on a blackberry from javascript?

Thanks, Ty

NEWEST DEVELOPMENT: Using "window.addEventListener("keyup",...)" or "document.addEventListener("keyup",...)" instead does not work.

Abbottson answered 26/10, 2011 at 17:22 Comment(1)
Great question. I've met that problem in android's 2.2 & 2.3 browser.Chirk
N
2

Strange... Some things I'd try:

  1. Ensure that Javascript is enabled on the Blackberry (it's usually disabled by default).

  2. Try using .charCode instead of .keyCode

  3. Try using document.onkeyup instead of window.onkeyup

Nippon answered 28/10, 2011 at 23:58 Comment(1)
Javascript is enabled, I also tried document instead of window, still not triggering the event at all.Abbottson
S
1

Blackberry seems to have some difficulties with javascript. If it's possible for you, I would suggess that you go with a library ( like JQuery ). Usually theses kind of library are made to be xbrowser compatible, they do the compatibility work for you.

If you must remain with pure javascript code, try to put an alert() in you GetKeyUp fonction to see if the onkeyup event is recognized.

Shortridge answered 28/10, 2011 at 23:28 Comment(4)
Unfortunately, I have to remain in pure js. =(Abbottson
The GetKeyUp event never fires, I put an alert at the beginning of that function and still nothing.Abbottson
What happen if you try other event (click, mousedown, etc..) ?Shortridge
My click events on other objects work fine. It just seems to be key eventsAbbottson

© 2022 - 2024 — McMap. All rights reserved.