javascript - Chrome Extension : Adding rows to a table on occurrence of an event -
i have background script background.js pops html page popup.html has script time.js. content script monitors onbeforeunload event upon url stored(along other data). time.js script loads stored data , puts them in table.
background.js
chrome.browseraction.setpopup({popup:"popup.html"}); popup.html
<!doctype html> <html lang="en"> <body> <div id='div'></div> <table id="datatable"></table> <script src="time.js"></script> </body> </html> time.js
loaddata(); function loaddata() { chrome.storage.local.get(["hrs","mins","secs","urls"], function(result) { var row = document.createelement('tr'); var col1 = document.createelement('td'); var col2 = document.createelement('td'); row.appendchild(col1); row.appendchild(col2); col1.innerhtml = result.urls; col2.innerhtml = result.hrs+":"+result.mins+":"+result.secs; document.getelementbyid("datatable").appendchild(row); }); } however, popup.html able display 1 row(0th row, guess) every time click on browser action icon. want append rows existing table. have seen few posts talk creating , appending new rows, none of them worked. tried store rowid , increment upon event worked fine row=table.insertrow(rowid) gave same problem. want know why happening , possible solution it.
edit : think problem maybe due fact popup.html loads every time click on browser action button(resetting previous table). but, have included popup inside background script , background scripts start running in background of browser once extension loaded(one instance). think popup.html should behave same way , paragraph/table_row added must remain intact.
ps- i'm new chrome extensions , if i'm missing here, i'd learn.
your assumption correct. popup.html loads every time. not possible 'include in background'. did set url can accomplished in manifest.json
there no persistence, have store information somewhere , recreate whole table every time popup loads.
save information in localstorage, chrome.storage or myriad of other persistence engines available.
Comments
Post a Comment