English 中文(简体)
重复/翻滚笔记本功能,以检查饼干是否变了
原标题:Repeating/looping javascript function to check if a cookie has changed

我试图制作一个脚本,每5秒钟重复一次。

The script that will be repeated will check to see if a cookie exists.
If the cookie does not exist, the page is redirected.
If the cookie does exist, nothing happens.

饼干很好,我唯一的问题就是它不重复!

我用jQuery来识别/检查饼干,这很好。

我想知道密码有什么问题

I have looked online many times, but have had no luck in finding what I need.
This is the cookie plugin I use: https://github.com/carhartl/jquery-cookie

var checkcookie = $.cookie( myCookie );

checklogin();
function checklogin(){
    setTimeout(function(){
        if(checkcookie == null){
            //if cookie not set
            window.location.href= / ;
        }
        else{
            //if cookie set
        }

    }, 5000);

checklogin();//to recall the script after it is done
}

或者如果有人有其他方法 检查饼干是否变了,我想知道!

问题回答

工作正常, 但您的 cookie 值不会改变 - 它设定了一次或永远。 试着将它包含在您的 < code> Demementout () 中 :

checklogin();

function checklogin(){
    setTimeout(function(){
        var checkcookie = $.cookie( myCookie );

        if(checkcookie == null){
            window.location.href= / ;
        }
        else{
            //if cookie set
        }

    }, 5000);

    checklogin(); //to recall the script after it is done
}

如果您在这样做时, 支票的调用必须在设置时间输出功能中进行, 否则它就会被立即调用 。

另外, i d 使用设定的 Interval 代替, 这样您就不需要您的递归函数 :

setInterval(function(){
    if(checkcookie == null){
        window.location.href= / ;
    }else{
        //if cookie set
    }
},5000);




相关问题
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.

热门标签