JS在第一次访问时重定向到启动页面

JS to redirect to a splash page on first visit?

本文关键字:启动 重定向 第一次 访问 JS      更新时间:2023-09-26

我正在尝试修改一些代码,以在用户第一次访问时将用户定向到"创建帐户"挤压页面。我想我很接近,但我需要一点帮助。关于我哪里出错了有什么建议吗?

<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: '/' });
});

好的 - 我一直在挖掘并找到一个不同的脚本。这是以防其他人试图做同样的事情:

<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');}

试试这个:

$(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"
    }
});

执行代码后将位置更改为另一个站点