Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save an option for background.html in popup?
    primarykey
    data
    text
    <p>I have a problem, what i cant solve yet. I have a popup page with a menu, and tabs, and there is a settings tab. On settings tab, i <strong>save</strong> some item to localstorage, one of them is notification_time for a desktop notification.</p> <p><strong>Note</strong>: i have no options page! </p> <p>My extension has this popup window and a background page, its function is to alert user with a desktop notification. I show notification in every 5,10,30 minutes, 1,2 hours etc. And this time should be chooseable on popup pages's options menu. The problem is, if 5 minutes is saved, and when i update to 10 minutes for example, than background.html is not updating himself! I rewrited code almost 20 times, but couldnt find solution. Heres a code sample,and a printscreen to get clear about my problem.</p> <p><img src="https://i.stack.imgur.com/pEZVj.jpg" alt="enter image description here"></p> <p><strong>popup</strong>: </p> <pre><code>$("#save_settings").click(function(){ var bgp = chrome.extension.getBackgroundPage(); localStorage.setItem("notifynumber",$("#notifynumber").val()); if($("#notify").attr('checked')){ localStorage.setItem('chbox','true'); } else { localStorage.setItem('chbox','false'); } if($("#notif_time_select :selected").val()!="default"){ bgp.setTime(parseInt($("#notif_time_select :selected").val())); } if($("#org_select :selected").val()!="default"){ localStorage.setItem('org',$("#org_select :selected").val().replace(/%20/g," ")); } }); </code></pre> <p><strong>Note</strong>: save_settings is a button, on the tab there is a checkbox (if checked then notifications are allowed, else diabled). There are two html select tags, one for choosing some data (org = organisation), and one, for selecting time. <code>"#notif_time_select"</code> is the html select tag, where i choose 5,10,30 minutes etc... </p> <p>So, whenever i click save button, i save checkbox state to localstorage,and i call one function from background page, to save time. :<code>bgp.setTime(parseInt($("#notif_time_select :selected").val()));</code></p> <p><strong>background page:</strong></p> <p>for saving time i use function setTime:</p> <pre><code>var time = 300000; // default function setTime(time){ this.time=time; console.log("time set to: "+this.time); } </code></pre> <p>after, i use setInterval to show notification periodically</p> <pre><code>setInterval(function(){ howmanyOnline("notify",function(data){ if(data&gt;localStorage.getItem("notifynumber")){ if (!window.webkitNotifications) { // check browser support alert('Sorry , your browser does not support desktop notifications.'); } notifyUser(data); // create the notification } if(localStorage.getItem('tweet')=='true'){ if(data&gt;localStorage.getItem("notifynumber")){ sendTweet(data,localStorage.getItem('org'),localStorage.getItem('ck'),localStorage.getItem('cs'),localStorage.getItem('at'),localStorage.getItem('ats')); } } }); },time); </code></pre> <p>The code inside setInterval works fine, the only problem is,that </p> <pre><code>},time); </code></pre> <p>is not updating well. If i change settings to show notifications in every 10 minutes, it stays on 5 minute. The only way is to restart the whole extension. How could i update setInterval's frequency without restarting the whole extension? Thanks Jim</p> <hr> <p>What if i save notif_time to localStorage too, and in background, i set up a listener, to listen for localStorage changes. Is there a way to listen for a particular localStorage item changes?!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload