我正在尝试修改一些代码,以便在首次访问时将用户引导至“创建帐户”页面。我想我很亲近,但我需要一些帮助。关于我哪里出错的任何建议?
<script type="text/javascript">
$(document).ready(function() {
// check cookie
var visited = $.cookie("visited")
if (visited == null) {
window.location = "content/content-article.asp?ArticleID=4998"
$.cookie('visited', 'yes');
alert($.cookie("visited"));
}
// set cookie
$.cookie('visited', 'yes', { expires: 10,000, path: '/' });
});
答案 0 :(得分:3)
好的 - 我一直在挖掘,发现了一个不同的脚本。这是为了防止其他人试图做同样的事情:
<script type="text/javascript">
function redirect(){
var thecookie = readCookie('doRedirect');
if(!thecookie){window.location = 'http://yournetwork.com/splash';
}}function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name){var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}window.onload = function(){redirect();createCookie('doRedirect','true','999');}
答案 1 :(得分:0)
试试这个:
$(document).ready(function() {
// check cookie
var visited = $.cookie("visited")
// set cookie
$.cookie('visited', 'yes', { expires: 10,000, path: '/' });
if (visited == null) {
$.cookie('visited', 'yes');
alert($.cookie("visited"));
window.location = "content/content-article.asp?ArticleID=4998"
}
});
执行代码后将位置更改为其他网站