javascript - 我有一个 IE 通知页面,但如何让用户跳过它并转发回索引?

标签 javascript html redirect

我有一个页面,通知 Internet Explorer 8 及以下版本的用户,使用 IE 查看我的网站时可能会出现问题,我正在使用 index.html 页面中的 HTTP 重定向,因此当他们点击索引时,他们转到页面“ie.html”。但是,如果他们单击“仍然继续”,我怎样才能将它们发送回索引而不再次重定向?

我在其他网站上看到他们会做类似 http://site.com/index.html?ignore_err 的事情

这是我需要做的吗?如果是这样,怎么办?

非常感谢。

最佳答案

我会设置一个 cookie ,因此选择加入将持续存在(只要用户拥有 cookie 或它过期)。我确信您不想通过请求更新到较新的浏览器来打击您的用户。 :)

来自:http://techpatterns.com/downloads/javascript_cookies.php

ie.html

function SetCookie( name, value, expires, path, domain, secure )
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

/*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
    expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

document.cookie = SetCookie('allowolderie','true','365','/','.example.com');

然后,在您的 IE conditional 内,在重定向之前检查cookie是否不正确:

index.html

<!--[if lte IE 8]>
<script type="text/javascript">
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;
}
if (readCookie('allowoldie') != 'true') {
    window.location = 'ie.html';
}
</script>
<![endif]-->

这样,您就不必将其放入 GET 字符串中并为用户维护它,尽管我认为您可以将其作为备份。

关于javascript - 我有一个 IE 通知页面,但如何让用户跳过它并转发回索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5695059/

相关文章:

javascript - 为什么我的无限轮播代码会破坏我的网页?

redirect - 非SEO反欺骗外部链接重定向: Status code?

javascript - 将 jsp 重定向到 servlet,然后到下一页

javascript - 使用 Angular js 弹出传单

带有文本换行符的 JavaScript 语法错误

javascript - 如何使用 Id 禁用输入框,同时使用克隆方法在表中添加新行?

html - 复选框在页面刷新时保持选中状态

javascript - 有没有办法将具有多个 if 语句的函数转换为箭头函数?

html - Foundation 6 中的列行类实际应用

ruby-on-rails - 如何在 Rails 3 中使用 AJAX 请求实现重定向响应?