I´currently trying to get my first chrome extension running. It is a very simple application to learn some Javascript and manage some data. I already managed to get my simple extension running but the problem is if I close the extension or click somewhere else on the page the data in the extension is lost. So I guess the extension restarts every time you click on the icon.
But I want the data to stay in my extension even if I switch to another page or close the HTML
-window of the extension.
How can I manage that the data will be stored during the runtime of my extension ?
Here is the code of my application. At this point the button just adds 5 to the stake
element to see if he value will be stored or not.
manifest.json
{
"manifest_version": 2,
"name": "Betting Extension",
"description": "This extension will analyze your account history",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab"
]
}
popup.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Tipico Analyzer</title>
<script src="popup.js"></script>
<link rel="stylesheet" href="Style.css">
</head>
<body style="width: 100px">
<p>stake: <span id="stake">0</span>€</p>
<p>profit: <span id="profit">0</span> €</p>
<p>winning: <span id="winning">0</span> €</p>
<button id="addPage">Add page</button>
</body>
</html>
popup.js
document.addEventListener('DOMContentLoaded', function(){
var checkPageButton = document.getElementById('addPage');
checkPageButton.addEventListener('click', function(){
d = document;
var stake = parseFloat(d.getElementById('stake').innerHTML);
document.getElementById('stake').innerHTML = stake + 5;
}, false);
}, false);