【发布时间】:2012-09-26 03:47:19
【问题描述】:
我正在使用本教程在我的网站上创建一个弹出消息:LINK
它应该只显示/弹出,当用户使用 IE7 或更低版本时,并且只有一次 - 所以我需要使用 cookie。
本教程使用了一个名为“Reveal”的 jQuery 插件,激活方式如下:
<script type="text/javascript">
$(document).ready(function() {
$('#button').click(function(e) { // Button which will activate our modal
$('#modal').reveal({ // The item which will be opened with reveal
animation: 'fade', // fade, fadeAndPop, none
animationspeed: 600, // how fast animtions are
closeonbackgroundclick: true, // if you click background will modal close?
dismissmodalclass: 'close' // the class of a button or element that will close an open modal
});
return false;
});
});
这个脚本附带的 HTML 是这样写的:
<div id="modal">
<div id="heading">
Are you sure you want to do that?
</div>
<div id="content">
<p>Clicking yes will make Comic Sans your new system<br> default font. Seriously, have you thought this through?</p>
<a href="#" class="button green close"><img src="images/tick.png">Yes, do it now!</a>
<a href="#" class="button red close"><img src="images/cross.png">No, I’m insane!</a>
</div>
</div>
我尝试使用 THIS 脚本自己将 cookie 添加到 "Reveal"-plugin,但没有成功:
<script type="text/javascript">
$(document).ready(function() {
if ( $.cookie ( 'first_visit' ) !== '0' ){
$('#modal').reveal({ // The item which will be opened with reveal
animation: 'fade', // fade, fadeAndPop, none
animationspeed: 600, // how fast animtions are
closeonbackgroundclick: true, // if you click background will modal close?
dismissmodalclass: 'close' // the class of a button or element that will close an open modal
});
$.cookie( 'first_visit' , '0' );
return false;
}
});
</script>
我做错了什么?我希望在 IE7 及以下版本上显示此弹出消息 - 仅在第一次访问该站点时显示。
【问题讨论】:
-
我没有看到任何可以阻止除 IE7 之外的其他浏览器查看此内容的内容。它只显示一次消息吗?浏览器问题,看api.jquery.com/jQuery.browser
-
真正的问题不是 IE7 - 更多的是 cookie 注册。
标签: php jquery cookies popup onload