开发者

Hooking "Open in new tab" and "Back"

I'd like to develop a Firefox Extension that does开发者_如何学JAVA 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.


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)


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://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).


It looks like you can implement the nsISHistoryListener interface to be notified when the user tries to go back.

OnHistoryGoBack

Notifies a listener when the user presses the 'back' button of the browser OR when the user attempts to go back one page in history through other means, either through scripting or by using nsIWebNavigation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜