I want to get the click coordinates from the toolbar icon in my Firefox extension.
The code I am using is given below:
//Toolbar code
<?xml version="1.0"?>
<overlay id="myext-toolbar-Overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<?xml-stylesheet href="chrome://myext/skin/myextToolbarButton.css" type="text/css"?>
<script src="chrome://myext/content/myextExtension.js" type="application/x-javascript" />
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="myext-button" class="toolbarbutton-1"
label="Button"
tooltiptext="Clip Web Page"
oncommand="myextExtension.showPopup(event);" >
</toolbarbutton>
</toolbarpalette>
</overlay>
On clicking the toolbar icon a popup is displayed. I want to display the popup at the position where the toolbar icon was clicked.
The
commandevent is not a mouse event, it can be triggered by different means (mouse and keyboard being the most common ones) so you cannot get the mouse position here. You could define a handler for theclickevent, rememberevent.screenX/event.screenYthere and use these in yourcommandevent handler then if they are available. But it is probably better to add apopupattribute to your button and let the system deal with it. Or just use<toolbarbutton type="menu">.