我有一个页面,通知 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/