Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7913765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:55:10+00:00 2026-06-03T13:55:10+00:00

I have a problem, what i cant solve yet. I have a popup page

  • 0

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 save some item to localstorage, one of them is notification_time for a desktop notification.

Note: i have no options page!

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.

enter image description here

popup:

$("#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," "));
        }
    });

Note: 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. "#notif_time_select" is the html select tag, where i choose 5,10,30 minutes etc…

So, whenever i click save button, i save checkbox state to localstorage,and i call one function from background page, to save time.
:bgp.setTime(parseInt($("#notif_time_select :selected").val()));

background page:

for saving time i use function setTime:

var time = 300000; // default
function setTime(time){
    this.time=time;
    console.log("time set to: "+this.time);
}

after, i use setInterval to show notification periodically

setInterval(function(){         
                howmanyOnline("notify",function(data){
                    if(data>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>localStorage.getItem("notifynumber")){
                            sendTweet(data,localStorage.getItem('org'),localStorage.getItem('ck'),localStorage.getItem('cs'),localStorage.getItem('at'),localStorage.getItem('ats'));
                        }
                    }
                });
    },time);

The code inside setInterval works fine, the only problem is,that

},time);

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


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?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:55:11+00:00Added an answer on June 3, 2026 at 1:55 pm

    Right now, setInterval only runs once, when your application loads. If you want intervals to fire at a new time interval, you should use clearInterval and then make a new call to setInterval.

    // set a new time, wipe out the old interval, and set a new interval
    function setTime(t) {
        window.time = t;
        clearInterval(notifInterval);
        notifInterval = setInterval(makeNotification, time);
    }
    
    // set first interval
    notifInterval = setInterval(makeNotification, time);
    
    function makeNotification() {
        // do what you need to make a notification
    }
    

    Here, notifInterval is a reference to the interval, returned by setInterval, that is used to clear it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that i cant solve :( I have a user control
I have a simple problem, yet i am unable to solve this. Either my
so i have a problem i cant solve i want my GUI app to
I have a problem and can't solve it alone. My teacher gives me one
i have a problem that i can't solve ! (sqlite3, but i think it
I have a problem here I can't solve. I have a database of houses
I have a problem, that I can't solve. I am writing an application that
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
I have a strange problem that I can't seem to solve. I've quite a
I have a very simple problem, but I can't seem to solve it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.