I'd like to do the equivalent of chrome.tabs.onUpdated in Firefox. tabs.on('ready', function(tab){}) does not work because it does not detect the back button. How do I fire an action on every page load such that it also detects the back button using the Firefox SDK?
4 回答
You'd have to use require('window-utils').WindowTracker
to all windows, filter for browser windows with the require('sdk/window/utils').isBrowser(window)
method, then listen to click events on the back button.
It's currently impossible, but will be possible in a future version of Firefox: https://github.com/mozilla/addon-sdk/commit/e4ce238090a6e243c542c2b421f5906ef465acd0
A bit of a late answer, but for anyone reading this now (from 2016), it is now possible to do using the SDK!
Using the High-Level API tabs
, you need to listen for the pageshow
event. (More about this on MDN)
An example:
tabs.on('pageshow', function(tab) {
// Your code here
})
It is very similar to the load
and ready
events, the main difference being that is is also fired when a page is loaded from BFCache
(which it is when the back button is pressed).
I think the following snippet gives the functionality of chrome.tabs.onUpdated
var tabs = require("sdk/tabs");
tabs.on('ready', function(tab){
console.log(tab.url);
});