简体   繁体   English

将 IE9 和 IE8 访问者重定向到同一网站的不同主页

[英]Redirect IE9 and IE8 visitors to different home page in same website

On my Wordpress site, Homepage has some JavaScripts and links that are not working on IE9.在我的 Wordpress 网站上,主页有一些 JavaScript 和链接在 IE9 上不起作用。 The theme developer saying that IE9 is not compatible and not taking the responsibility.主题开发者称IE9不兼容不承担责任。

Now, I have created another page with the same exact look but no Javascript on that.现在,我创建了另一个具有相同外观但没有 Javascript 的页面。 I want to redirect IE9 user to that page when they open the site.我想在 IE9 用户打开网站时将其重定向到该页面。

I tried different codes in header.php one of the code is我在 header.php 中尝试了不同的代码,其中一个代码是

<script type="text/javascript">
  if (navigator.userAgent.indexOf('MSIE') !=-1){
    window.location = "http://newpage.com"
  }
</script>

Problem is, this code redirect all website links to the redirected link but I only want to redirect the home page.问题是,此代码将所有网站链接重定向到重定向链接,但我只想重定向主页。

I will really appreciate if someone can help.如果有人可以提供帮助,我将不胜感激。

Thank you.谢谢你。

As per Phiter's comment, this is something that can and probably should be done on the server side with a redirect, but if you really want to do it on the client side, simply expand your test case to compare the current window location: 根据Phiter的评论,这可以并且应该通过重定向在服务器端完成,但是如果您真的想在客户端执行此操作,只需扩展测试用例以比较当前窗口位置即可:

if (navigator.userAgent.indexOf('MSIE') !=-1 
    && window.location === "http://homepage.com"){
  window.location = "http://newpage.com"
}

This could be done with an exact match like above, or a regular expression. 可以使用上述完全匹配或正则表达式来完成。

Redirection working after putting that code directly on my homepage. 将代码直接放在我的首页后,重定向工作正常。 If I put this code in Header of theme then it will redirect all web pages. 如果我将此代码放在主题标题中,则它将重定向所有网页。

if (navigator.userAgent.indexOf('MSIE') !=-1){
window.location = "http://newpage.com"

} }

But this is only working on IE9 and not on IE8.Any clue. 但这仅适用于IE9,而不适用于IE8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM