English 中文(简体)
如何为背景保留选择。 html
原标题:How to save an option for background.html in popup?

我有一个问题,可以解决。 我有一页烟.,有一张菜单和制片,有一片环境。 表格,isave 某些地方储存物品中有一个是通知——时间是进行桌面通知。

<<>>:无选择页!

我的延伸有这个人满为患的窗口和背景网页,其功能是向用户发出桌面通知。 我每5,10,30分钟,1,1,1小时,均作通知。 时间应当选择在百页选择菜单上。 如果节省了5分钟,如果更新到10分钟,问题就好像是背景。 html没有更新自己! 我改写了差不多20倍的法典,但有可能找到解决办法。 这里是一部法典样本,还有一部印刷屏幕,以了解我的问题。

“entergraph

<<>popup>/strong>:

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

<说明>:除设计外,在表格上有一个检查箱(如果检查时允许通知,则可以分开)。 选择时间为:选择某些数据(org=组织)和选择时间。 <代码>#notif_time_select> is the html selected tag, where i choose, 10,30分钟...

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()));

<>strong>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);
}

之后,即使用间隔定期通知

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);

该守则在规定的范围之内 平均工作罚款是唯一的问题,即:

},time);

尚未更新。 如果变化环境每10分钟都有通知,则时间为5分钟。 唯一的办法是重新开始整个延期。 如何在不重新开始整个延期的情况下更新间隔期的频率? 成就 Jim


当地时间 储存,并在背景之下设立一个听众,听取当地的意见 储存变化。 是否有办法聆听某个地方的人的声音 储存项目的变化!

最佳回答

现在,setInterval,在您提出申请时只运行一次。 如果你想要在新的间隔时间交火,你应使用<代码>clearInterval,然后用新的电话打 Interval

// 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
}

此处,notif Interval系指用于加以澄清的通过setInterval回归的间隔。

问题回答

The source code in your question is not completed, but I guess you called setInterval() and then modified window.time in the background page.
Your window.time is not an object but a number value, and setInterval() can t "see" changes of window.time after invocation.

Try this:

function onTimeout() {
    // do your notification.

    setTimeout(onTimeout, time);
}

setTimeout(onTimeout, time);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签