本文介绍了JS首次访问时重定向到初始页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试修改一些代码,以便在首次访问时将用户引导到创建帐户挤压页面。我想我很近,但我需要一点帮助。对于我出错的地方有任何建议吗?
I'm trying to modify some code to direct users to a "create an account" squeeze page on their first visit. I think I'm close, but I need a little help. Any advise on where I went wrong?
<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: '/' });
});
推荐答案
OK - 我不断挖掘,发现一个不同的脚本工作。这是为了防止别人试图做同样的事情:
OK - I kept digging and found a different script that worked. Here it is in case someone else is trying to do the same thing:
<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');}
这篇关于JS首次访问时重定向到初始页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!