views:

228

answers:

3

I'd like to develop a Firefox Extension that does things when a link click opens a new tab as the result of the link's attributes, and also when "Back" button (or equivalent) is pressed.

How can I hook these two things in an extension?

Update: I've started a bounty - I hope the answer can lead to some hidden documentation site for Firefox Add-Ons. A site that is not Firefox codebase, that is. And not a collection of all extensions ever written.

+2  A: 

I'll try to answer and give you some tracks, but be aware that it can depend on your firefox version number (I know you're not looking for MDC page, and I know it's not always well-documented, but here's what I found).

  • New tab : you have to add an eventListener in some initialization function, and reference the action that you want to call. This way you don't have to worry about how the new tab was called
  • Detect Back button pressed : (new feature since Firefox 3.5) add a progress listener on all tabs to detect a locationChange, and then play with "Places" the new history system (since Firefox 3) to compare and see if the new URI is the same as the previous one. Don't forget you can go back with "Del" or "Alt"+"LeftArrow" so you can't really re-implement the Back Button action (otherwise you could add a XUL overlay and redefine what you need, but I've never done that before)
Baztoune
The thing I need to do is to catch the browser after it realizes it needs to go back (whether from back button, alt-left or Del) but before it actually attempts to go back.
Arkadiy
Hmm not sure it will be possible without some tricky solution. I can't help you more I think, but you could find help on irc.mozilla.org, where mozilla developers talk about difficulties and other (maybe it's not the best period).
Baztoune
+2  A: 

It looks to me like you want to avoid using the progress listener because you want to be able to react to back even when there is no page to go back to.

If this is the case, have you tried replacing the new tab with a temp URL of some kind?

To explain what I mean:

  1. User clicks opens new tab to http://www.google.com
  2. Redirect to http://cannotwork/?http%3A//www.google.com
  3. Save as a location
  4. On any request for http://cannotwork/ send to supplemented location

Just kind of throwing out ideas here. Good luck.

Also there is a Back to Close addon for earlier versions of FF, that replaced the back button with close when you were at the "start". It may be anoter decent idea. The only problem was he could not catch del/back on mouse. So he recommended rebinding the mouse button to Alt+Left (Which was caught).

Guvante
A: 

try this addon

http://www.mousegestures.org/

it lets you assign java code and/or keystrokes to mouse gestures ..... might not be your ideal solution, but i think it will help you accomplish your needs

CheeseConQueso