在第一页加载时触发jquery脚本,然后对该用户再也不会触发? [英] Fire jquery script on first page load, and then never again for that user?

查看:86
本文介绍了在第一页加载时触发jquery脚本,然后对该用户再也不会触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的网站上使用以下jQuery Modal Window脚本: http://www .zurb.com/playground/reveal-modal-plugin

I'm using this jQuery Modal Window script on my site: http://www.zurb.com/playground/reveal-modal-plugin

当前,当用户单击链接时,它将激活模式窗口.但是,我想将其修改为在首次加载页面后自动运行.但是,该同一用户随后对同一页面的访问将不会再次激活该脚本.我大概可以自己弄清楚如何使其在页面加载中运行.但是让它只发射一次,然后再也不会发射是我不熟悉的事情.

It currently activates a Modal Window when the user clicks on a link. However, I want to modify it to automatically run once the page is loaded for the first time. But subsequent visits to that same page by that same user will not activate the script again. I could probably figure out how to get it to run on page load myself. But getting it to only fire one time, and then never again is something I'm not familiar with.

任何帮助将不胜感激.

推荐答案

您需要在该客户端的浏览器中具有持久性,或者如果这是用户具有配置文件的Web应用程序,则需要跟踪其状态服务器端.

You would need something persistent in that client's browser, or if this is a web application where the user has a profile, you'd need to track the state on the server side.

如果您在客户端进行所有操作,则可能会使用Cookie.您可以从服务器端或在JavaScript中设置cookie.

If you're doing it all client side, you'd likely use a cookie. You can either set the cookie from the server side, or in JavaScript.

以下是一些已设置的cookie/获取cookie功能:

Here are some set cookie/get cookie functions:

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function getCookie(cookieName) {
 var theCookie=" "+document.cookie;
 var ind=theCookie.indexOf(" "+cookieName+"=");
 if (ind==-1) ind=theCookie.indexOf(";"+cookieName+"=");
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(";",ind+1);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+2,ind1));
}

因此,您可以将其像这样绑在一起:

So, you would tie it together like this:

$(function() {

     var skipModal = getCookie('skipModal');
     if (!skipModal) { // check and see if a cookie exists indicating we should skip the modal
         // show your modal here


         setCookie('skipModal', 'true', 365*5); // set a cookie indicating we should skip the modal
     }
});

这篇关于在第一页加载时触发jquery脚本,然后对该用户再也不会触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆