On Jun 7, 3:24 am, shiweiwei <
shiweiwe...@gmail.com> wrote:
> I am not sure I understand this correctly but the final conclusion is
> the "magic ifram" didn't solve the problem.
Actually, it seems to work for me. Try this extension code for
example :
manifest.json:
{
"name": "SavePopupContent",
"version": "0.0.1",
"description": "POC for Saving a popup content",
"background_page" : "background.html",
"browser_action": {
"default_popup": "popup.html"
}
}
background.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Background page</title>
</head>
<body></body>
</html>
popup.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Popup page</title>
</head>
<body>
<em>Randoms!</em>
<hr>
<script src="popup.js"></script>
</body>
</html>
popup.js:
var bgPage = chrome.extension.getBackgroundPage();
// listeners to save/restore document.body
window.addEventListener("unload", function(event) {
chrome.extension.getBackgroundPage().docBody = document.body;
});
window.addEventListener("load", function(event) {
var
docBody = document.body,
lastDocBody = bgPage.docBody;
if (lastDocBody)
docBody.parentElement.replaceChild(document.importNode(lastDocBody,true),
docBody);
});
// code example
window.addEventListener("load", function(event) {
document.body.innerHTML += Math.floor(Math.random() * 10) + "<br>";
});
Each time you will open the popup, a new random number will be added
into the "persistent" popup.
If you want to keep variables then all you have to do is to store
variables in the "bgPage" variable.