Javascript 如何将所有 IE 用户重定向到新页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7637585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 03:00:16  来源:igfitidea点击:

How to Redirect all IE users to a new page

javascriptinternet-explorerbrowserredirect

提问by Gregg

My programmer is on vacation so I need your help! I discovered a page that has a bug for IE users. I want to redirect all IE users to a different page.

我的程序员正在休假,所以我需要你的帮助!我发现了一个对 IE 用户有错误的页面。我想将所有 IE 用户重定向到不同的页面。

How can I do this? I searched all through Google and Stackoverflow and cannot find an answer. (I found some scripts, and tried them, but none worked).

我怎样才能做到这一点?我通过 Google 和 Stackoverflow 搜索了所有内容,但找不到答案。(我找到了一些脚本,并尝试了它们,但没有一个奏效)。

回答by Ayman Safadi

Try:

尝试:

<!--[if IE]>
<script type="text/javascript">
window.location = "http://www.google.com/";
</script>
<![endif]-->

回答by ChrisW

Or, a non-JS solution, put the following in your headsection:

或者,非 JS 解决方案,将以下内容放入您的head部分:

<!--[if IE]>
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com">
<![endif]-->

回答by owltuna

A reminder that the [if IE] solution does not apply to IE 10 or greater. This can be very annoying for "features" that have not been fixed by IE 10. I am going to try the php and java solutions and re-comment.

提醒一下,[if IE] 解决方案不适用于 IE 10 或更高版本。对于 IE 10 尚未修复的“功能”,这可能非常烦人。我将尝试 php 和 java 解决方案并重新评论。

回答by NullIsNot0

I put this in header and it works for all IE versions:

我把它放在标题中,它适用于所有 IE 版本:

<!-- For IE <= 9 -->
<!--[if IE]>
<script type="text/javascript">
    window.location = "https://google.com";
</script>
<![endif]-->

<!-- For IE > 9 -->
<script type="text/javascript">
    if (window.navigator.msPointerEnabled) {
        window.location = "https://google.com";
    }
</script>

回答by O-mkar

For Internet Explorer 10 this one works well

对于 Internet Explorer 10,这个效果很好

<script type="text/javascript">
   if (navigator.appName == 'Microsoft Internet Explorer')
   {

      self.location = "http://www.itmaestro.in"

   }
</script>

回答by Dennis

Server-side solution using PHP that's guaranteed to work on all browsers:

使用 PHP 的服务器端解决方案保证适用于所有浏览器:

<?
if ( preg_match("/MSIE/",$_SERVER['HTTP_USER_AGENT']) )
        header("Location: indexIE.html");
else
        header("Location: indexNonIE.html");
exit;
?>

回答by rjhdby

Support for conditional comments has been removed in Internet Explorer 10 standards

Internet Explorer 10 标准中删除了对条件注释的支持

I'm use this dirty hack for redirecting IE10+ users

我正在使用这个肮脏的黑客来重定向 IE10+ 用户

<script type="text/javascript">
    var check = true;
</script>
<!--[if lte IE 9]>
<script type="text/javascript">
    var check = false;
</script>
<![endif]-->
<script type="text/javascript">
    if (check) {
        window.location = "page_for_ie10+.html";
    }
</script>