如何在javascript Cookie中保存活动?

时间:2016-11-17 01:44:08

标签: javascript jquery cookies

此弹出窗口。客户端在30秒内访问该站点后,将自动出现一个窗口。关闭窗口后消失。但是当客户端转到另一个页面时,脚本开始工作(刷新页面后)。如何记住在访问客户的网站时关闭模态窗口?

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.example.nariman.myapplication"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'net.time4j:time4j-calendar:4.20'
    compile 'net.time4j:time4j-olson:4.0'
    testCompile 'junit:junit:4.12'
}

1 个答案:

答案 0 :(得分:0)

JavaScript中的

编写一个存储cookie的函数(如果它不存在),然后设置持续30分钟的cookie。 **写未经测试

// get cookie 
var cookie_email = Cookies.get('example');

if(!cookie_email){

 // show popup
 var delay_popup = 5000;setTimeout("document.getElementById('parent_popup').style.display='block'", delay_popup);

 // set cookie to expire after 30 mins 
 var date = new Date();
 var minutes = 30;
 date.setTime(date.getTime() + (minutes * 60 * 1000));
 $.cookie("example", "foo", { expires: date });

}