简体   繁体   中英

In Chrome extension determine if the user clicked the browser's Back or Forward button

How can I know whether the user clicked back/forward button in Chrome from within my Chrome Extension?

The only API that could give me any such info is the chrome.webNavigation.onCommitted which in the case of when the back or forward button are clicked, sends a NavigationQualifier containing the string 'forward_back' . The problem here is that I'm not able to distinguish between the two buttons.

You could use the tabs API's onUpdated event if that's good enough for you.

Alternatively, you could use the HTML5 history API and register a window.onpopstate handler. Do that from within a content script that runs before the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM