Mike Repass
Mike Repass

Reputation: 6982

How to programmatically invoke a Firefox button/addon

For a given button inside Firefox 4, how do I discover the appropriate way to simulate a click using XPCom/JavaScript? I'd like to programmatically invoke a dialog which is currently only reachable by clicking a toolbar button.

More info: I am happily using Mozilla's experimental F1 sharing extension from here:

http://f1.mozillamessaging.com

But I'd like to craft a custom keybinding or programmatic invocation for the share dialog (basically I want to hide my navigation bar but still invoke F1 easily).

I cannot find any straightforward way to do this? I suspect that I just need to peek at (the equivalent of) the onClick handler for the default button and then invoke that in my own XPCom code ... but this seems undiscoverable.

Any help would be much appreciated.

Upvotes: 2

Views: 686

Answers (1)

Tyler
Tyler

Reputation: 22136

Peeking at the onclick handler might work, if they did it that way. But if they added the functionality using addEventListener then it would not. In that case, your best bet might be to use dispatchEvent to simulate the user clicking on that button.

https://developer.mozilla.org/en/DOM/element.dispatchEvent

Upvotes: 1

Related Questions