即使更改了内容,Chrome扩展程序弹出窗口也会重置 [英] Chrome extension popup resets even after changing its contents
本文介绍了即使更改了内容,Chrome扩展程序弹出窗口也会重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的chrome扩展程序中,我不得不从背景更改弹出html.更改将生效,然后再次单击扩展程序图标,将显示未更改的弹出窗口.为什么?
In my chrome extension, I had to change popup html from background. Changes affects then and after clicking again in extension icon, the unchanged popup is showing. Why?
推荐答案
每次您从弹出窗口中单击时,都会重置该窗口.解决此问题的一种方法是使用您的后台页面将会话数据存储在popup.js中,执行以下操作:
Every time you click away from your popup window, the window is reset. A way to fix this would be to use your background page to store session data, in your popup.js, do something like this:
chrome.runtime.getBackgroundPage(function(bg){
if(bg.sessionDataHTML){
document.body.innerHTML = bg.sessionDataHTML;
}
setInterval(function(){
bg.sessionDataHTML = document.body.innerHTML
},1000);
//do the rest of your work here.
})
通常,我会在该匿名函数内的弹出窗口中执行所有操作,以使我能够访问在我的后台页面中定义的库.
I typically do everything in my popup inside that anonymous function to give me access to the libraries defined within my background page.
这篇关于即使更改了内容,Chrome扩展程序弹出窗口也会重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文