0

I have a wordpress site and I need the homepage ONLY to be redirected to a different homepage if the browser is IE8.

This is what i have in the header, but, it redirects every page if someone is on ie8 because the header is on every page.

<script type="text/javascript">
<!--
if ((navigator.userAgent.match("MSIE 8.0"))) {
  location.replace("http://website.com/ie8/");
}
-->
</script>

Since this is in the header, every page on my site gets redirected to website.com/ie8. I only need the homepage to do it. Thoughts? Thanks.

Narzard
  • 181
  • 3
  • 16

2 Answers2

0
if (navigator.userAgent.match("MSIE 8.0") && window.location.pathname === '/') {
  location.replace("http://website.com/ie8/");
}
jgillich
  • 63,850
  • 5
  • 53
  • 80
0

(I would recommend you do redirection from PHP by using get_browser() (or checking $_SERVER['HTTP_USER_AGENT'] directly) and then redirect as explained here: How to make a redirect in PHP?

That will be faster, more efficient, and more reliable than via js.

Community
  • 1
  • 1
Jorge Orpinel Pérez
  • 5,700
  • 1
  • 19
  • 35