Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将所有IE用户重定向到新页面_Javascript_Internet Explorer_Browser_Redirect - Fatal编程技术网

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

Javascript 如何将所有IE用户重定向到新页面,javascript,internet-explorer,browser,redirect,Javascript,Internet Explorer,Browser,Redirect,我的程序员正在度假,所以我需要你的帮助!我发现一个页面有IE用户的bug。我想将所有IE用户重定向到不同的页面 我该怎么做?我搜索了整个谷歌和Stackoverflow,没有找到答案。(我找到了一些脚本,并尝试了它们,但都不起作用) 试试看: <!--[if IE]> <script type="text/javascript"> window.location = "http://www.google.com/"; </script> <![endif

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

我该怎么做?我搜索了整个谷歌和Stackoverflow,没有找到答案。(我找到了一些脚本,并尝试了它们,但都不起作用)

试试看:

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

或者,对于非JS解决方案,请将以下内容放在您的
标题中
部分:

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

使用PHP的服务器端解决方案,保证可在所有浏览器上运行:

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

对于Internet Explorer 10,此项功能运行良好

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

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

   }
</script>

如果(navigator.appName==“Microsoft Internet Explorer”)
{
self.location=”http://www.itmaestro.in"
}

提醒您[如果IE]解决方案不适用于IE 10或更高版本。这可能是非常恼人的“功能”,还没有被IE 10修复。我将尝试php和java解决方案并重新评论。

我将其放在标题中,它适用于所有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>

if(window.navigator.msPointerEnabled){
window.location=”https://google.com";
}

我正在使用这个肮脏的黑客重定向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>

var检查=真;
如果(检查){
window.location=“page\u for_ie10+.html”;
}
js代码:

<script>if (/*@cc_on!@*/false || (!!window.MSInputMethodContext && !!document.documentMode)){window.location.href="https://....html";}</script>
if(/*@cc_on!@*/false | |(!!window.MSInputMethodContext&&!!document.documentMode)){window.location.href=”https://....html";}

你也可以使用这个

也许修复ie bug会更容易/更好。你可以试着问另外一个关于这个问题的问题,PHP是一个选项吗?因为javascript解决方案只有在启用javascript的情况下才能工作…@Dennis,我建议使用非JS解决方案作为答案below@ChrisW:+1。但您也可以禁用元刷新。还有一些浏览器不尊重标签。例如,它在Google Chrome中不起作用。@Dennis-谢谢,我没有意识到Chrome不尊重它!我没想过那样做!哈利路亚!!!成功了!非常感谢你-我知道有一个简单的方法可以做到这一点@格雷格:请将解决您问题的帖子标记为回答。请注意,这是针对IE9或更低版本的。HTTP_USER_代理不能完全保证工作,可以编辑(例如,显然有一种方法(,尽管我没有测试过),尽管我怀疑很多人(尤其是IE用户!)我想使用本地代理也是一种选择。但对大多数人来说也不太可能。所有这些都是假设Gregg首先使用PHP。我的IE11默认用户代理字符串是“Mozilla/5.0(Windows NT 6.1;WOW64;Trident/7.0;rv:11.0),就像Gecko”(WTF IE),所以这对它不起作用。不管怎样,你可以很容易地更改那里的用户字符串,所以这不是一个保证的解决方案。太好了,我正在寻找非JS解决方案:)你不知道在加载主页之前是否有任何方法重定向它吗。IE8显示主索引页一秒钟,然后重定向。它看起来更好,更轻。