【发布时间】:2012-03-15 12:44:14
【问题描述】:
我的网站现在在主页运行 javascript 弹出窗口,现在我想做当用户单击主页时,用户将转到主页并显示 javascript pop,但单击关闭后,当用户再次单击主页时,此 javascript 不会运行,此脚本仅活动一天。
那么,如何将 cookie 与我的 javascript 弹出窗口集成?
*这个弹出窗口运行完美,但只剩下 cookie 脚本
网址http://tsubamecorp.com/home/index.php?route=extras/blog/getblogcategory&blogpath=41
这是我的 javascript 弹出窗口:
<script>
var $xx = jQuery.noConflict();
$xx(document).ready(function() {
//select all the a tag with name equal to modal
$xx('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $xx(this).attr('href');
//Get the screen height and width
var maskHeight = $xx(document).height();
var maskWidth = $xx(window).width();
//Set heigth and width to mask to fill up the whole screen
$xx('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$xx('#mask').fadeIn(1000);
$xx('#mask').fadeTo("slow",0.90);
//Get the window height and width
var winH = $xx(window).height();
var winW = $xx(window).width();
//Set the popup window to center
$xx(id).css('top', winH/2-$xx(id).height()/1);
$xx(id).css('left', winW/2-$xx(id).width()/2);
//transition effect
$xx(id).fadeIn(1000);
});
//if close button is clicked
$xx('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$xx('#mask').hide();
$xx('.window').hide();
});
});
</script>
<script type="text/javascript">
window.onload = function() { $xx('a[href="#dialog1"]:eq(0)').click();
}
</script>
【问题讨论】:
-
不太确定你的问题:“这个脚本只激活一天。”,你的意思是在一天之内,每个用户可以看到弹窗一次,而另一天,会看到再来一次?
-
你说的cookie在哪里。请更清楚地解释您的问题,标题有点误导。你想一键关闭弹窗吗?
-
好的,你去这里tsubamecorp.com/home/index.php?route=extras/blog/… ..问题是当用户单击主页按钮时,每次用户单击时都会显示此弹出窗口..我希望仅在一天内运行一次此弹出窗口。 .
-
我知道解决方案是设置 cookie..但我不知道该怎么做..
标签: javascript cookies setcookie