【问题标题】:JS to redirect to a splash page on first visit?JS 在第一次访问时重定向到启动页面?
【发布时间】:2012-06-06 21:16:15
【问题描述】:

我正在尝试修改一些代码,以便在用户首次访问时将其引导至“创建帐户”挤压页面。我想我已经接近了,但我需要一点帮助。关于我哪里出错了有什么建议吗?

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

【问题讨论】:

  • 你必须告诉我们出了什么问题
  • 你遇到了什么错误?
  • 难道10,000 实际上应该是100001e4
  • 我没有收到错误,只是没有重定向。这是测试页面:pitchrate.com/content/content-article.asp?ArticleID=4999
  • 和更新的代码:

标签: javascript redirect cookies


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    试试这个:

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

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

    【讨论】:

    • 我尝试了这些更改以及将 10,000 更改为 1e4 - 仍然没有乐趣。
    猜你喜欢
    • 2014-09-18
    • 2019-03-16
    • 1970-01-01
    • 2013-03-21
    • 2022-12-10
    • 1970-01-01
    • 2018-12-04
    • 1970-01-01
    • 2011-08-07
    相关资源
    最近更新 更多