问题
For now, I've only found a way to listen to "reload" event using:
chrome.webNavigation.onCommitted.addListener(function(details) {
if (details.frameId == 0) {
if (details.transitionType == "reload") {
// do something
}
}
});
What about "go back" and "go next" events? I'm looking for a Firefox's nsISHistoryListener
alternative in Chrome.
Edit: Submitted a feature request to Chromium.
回答1:
You could use the window.beforeunload event to capture when a user intends to navigate to another page (which would be triggered when using the back and forward buttons).
window.onbeforeunload = function () {
// do something
};
There is no way to get the target destination when using onbeforeunload
.
More info here: Is there a cross-browser onload event when clicking the back button?
来源:https://stackoverflow.com/questions/8960602/how-to-listen-to-history-events-like-go-back-go-next-in-chrome-extension