mik*_*ols 3 javascript jquery jquery-cookie magnific-popup
我有一个简报注册表单,我想每15天加载一次(弹出),否则可能会有点恼人.我目前正在使用此jquery代码在页面加载时加载弹出窗体.
<div id="test-popup" class="white-popup mfp-hide">
Popup Form
</div>
<script>
jQuery(window).load(function(){
jQuery.magnificPopup.open({
items: {src: '#test-popup'},type: 'inline'}, 0);
});
</script>Run Code Online (Sandbox Code Playgroud)
这在每次访问页面时加载表单时工作正常,但我想限制这一点,以便新用户每15天看一次.不确定15天是最好的做法我想出的东西?
您可以使用localStorage执行此操作.
$(window).on('load', function() {
var now, lastDatePopupShowed;
now = new Date();
if (localStorage.getItem('lastDatePopupShowed') !== null) {
lastDatePopupShowed = new Date(parseInt(localStorage.getItem('lastDatePopupShowed')));
}
if (((now - lastDatePopupShowed) >= (15 * 86400000)) || !lastDatePopupShowed) {
$.magnificPopup.open({
items: { src: '#test-popup' },
type: 'inline'
}, 0);
localStorage.setItem('lastDatePopupShowed', now);
}
});
Run Code Online (Sandbox Code Playgroud)
<div id="test-popup" class="white-popup mfp-hide">
Popup Form
</div>
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到一个有效的例子:http://codepen.io/caio/pen/Qwxarw
| 归档时间: |
|
| 查看次数: |
2160 次 |
| 最近记录: |