Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
marc123
Posts: 3
Registered: ‎12-31-2008
My Device: Not Specified
Accepted Solution

Javascript - Mouse Coordinates

Hello,

 

I'm using a Blackberry 9000 with the Hotspot Browser and I'm lokking for a way to get the mouse coordinates when the user clicks somewhere in the document. Something like event.clientX or event.pageX in other browsers...

 

Thanks in advance,

Marc

Developer
Posts: 107
Registered: ‎09-25-2008
My Device: Not Specified

Re: Javascript - Mouse Coordinates

Both clientX/clientY and screenX/screenY should work.

http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MouseEvent

Do you have sample code that doesn't work?
New Developer
marc123
Posts: 3
Registered: ‎12-31-2008
My Device: Not Specified

Re: Javascript - Mouse Coordinates

Very fast reply. Thanks!

 

I found the problem with your hint. The problem are the events:

 

Works:

<img id="img" src="" onClick="mX=event.clientX;mY=event.clientY;">


Doesn't work:

document.ondblclick= ...;


Doesn't work:
<img id="img" src="" ondblclick="mX=event.clientX;mY=event.clientY;">

 

Do you know why ondblclick never fires?

 

Marc

 

Developer
Posts: 107
Registered: ‎09-25-2008
My Device: Not Specified

Re: Javascript - Mouse Coordinates

According to the guide at http://na.blackberry.com/eng/deliverables/5682/HTML_Reference.pdf the ondblclick attribute is not supported. I would imagine it's pretty hard to double-click using the trackball anyway, so maybe you could use single-clicks instead?
New Developer
marc123
Posts: 3
Registered: ‎12-31-2008
My Device: Not Specified

Re: Javascript - Mouse Coordinates

Yes, i can use a single click.

 

A last other question:

 

The Reference says that the "body" tag supports the "onkeypress" events, but this...

 

<body onkeypress="javascript&colonalert('Hello')">

 

.. didn't work. I was only able to get the  "onkeypress" event in an "input" tag?

 

Marc

 

 

 

Developer
Posts: 107
Registered: ‎09-25-2008
My Device: Not Specified

Re: Javascript - Mouse Coordinates

Hm, interesting. Most of the time when I pressed a key it activated a hotkey (e.g. pressing 's' brings up the settings), so I assume the keypress doesn't actually get to the page unless something on the page has focus. Since only input fields get focus, that's when you end up getting the keypress events.