简体   繁体   English

清除Chrome Extension PopUp页面上的localStorage关闭

[英]clear localStorage on Chrome Extension PopUp page close

I have created a Google Chrome Extension with popup page and popup,js 我创建了一个带有弹出页面和popup,js的Google Chrome浏览器扩展程序

I capture date from different pages, store them in localStorage and show on the popup page. 我从不同的页面捕获日期,将它们存储在localStorage中并显示在弹出页面上。 So, I need to clear it every time I am on a different page, so that it should not show the previous value. 因此,每次我在不同的页面上时都需要清除它,以便它不显示以前的值。 I have tried various ways to clear localStorage like 我尝试了各种方法来清除localStorage,例如

by using window.onload and window.onbeforeunload. 通过使用window.onload和window.onbeforeunload。 But, it is not working. 但是,它不起作用。 Please help me by telling the way to do the same. 请告诉我这样做的方法,以帮助我。

It looks like you should use the onActivated event to figure out when the active tab changes. 看来您应该使用onActivated事件确定活动选项卡何时更改。 Put the code in you extension's background page. 将代码放在扩展程序的后台页面中。

chrome.tabs.onActivated.addListener(function callback)

Here is some more documentation: http://developer.chrome.com/extensions/tabs.html#event-onActivated 这是更多文档: http : //developer.chrome.com/extensions/tabs.html#event-onActivated

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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