views:

230

answers:

1

How do I get to list down the stored records in the for loop?

Basically I want it to list down the records like this:

'<div id="record_' + number + '">' + localstorage value + '</div>'

The number in the class should add 1 every record, e.g. 1, 2, 3, 4 every record it lists down, and so on.

The localstorage value should show the localStorage[] but the problem is, the localStorage name has the same, e.g.

(clicks on button)

it will save the value of the URL into a localStorage

I then open the application and shows the window.html

inside there is list of stored records by using this:

'<div id="record_' + number + '">' + localstorage value + '</div>'

INCLUDING the record number to add per record 1, 2, 3, etc... like this:

<div id="record_1">localstorage value</div>
<div id="record_2">localstorage value</div>
<div id="record_3">localstorage value</div>
<div id="record_4">localstorage value</div>
<div id="record_5">localstorage value</div>
<div id="record_6">localstorage value</div>

etc...

EDIT:

for (var i = 1; i < localStorage.length; i++) {
document.write('<div id="record_' + i + '">' + i + '<span style="float:right;"><ahref="#" onclick="javascript:clear(' + i + ');">Delete</a></span></div>');
}

window.addEventListener("load", windowLoaded, false);
function windowLoaded() 
{
  chrome.tabs.getSelected(null, function(tab) 
  {
    var btn = '<a href="' + tab.url + '" onclick="Save(\'' + tab.url + '\');">Add to Favourites</a>';
    document.getElementById('current-link').innerHTML = '<p>' + btn + '</p>';
  });
}

function Save(url)
{
    localStorage.setItem("cilium-favs", url);
}
A: 

You can iterate localStorage as well.

for (var i=0; i < localStorage.length; i++) {
  console.log(localStorage.key(i));
}

Is that what you want?

Mohamed Mansour
I've edited the code above, I can't get it to save the url into the localstorage, please provide me some examples, I hardly can find good tutorials for good storage instead of chrome documentation all the time. Thanks.
Jamie