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
  • 213
  • 5
  • 18

2 Answers2

0
if (navigator.userAgent.match("MSIE 8.0") && window.location.pathname === '/') {
  location.replace("http://website.com/ie8/");
}
jgillich
  • 71,459
  • 6
  • 57
  • 85
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
  • 6,361
  • 1
  • 21
  • 38