-1

I want users to be redirected to a different webpage if they are using a PS3

here is the code I have been trying to use

<script language=javascript>
<!--
if ((navigator.userAgent.match(/iMozilla/i)) || (navigator.userAgent.match(/iPLAYSTATION 3/i))) {
   location.replace("http://example.com");
}
-->
</script>

A list of the user agents for the PS3 can be found here http://www.useragentstring.com/pages/Playstation%203/

I cant seem to get it to work so what am I doing wrong?

c69
  • 19,951
  • 7
  • 52
  • 82
Matu
  • 17
  • 9

1 Answers1

2

You could try something like this:

<script language=javascript>
    var uAgent = navigator.userAgent;
   if (uAgent.indexOf("PLAYSTATION") != -1) {
      window.location = ("http://example.com");
   }
</script>

It may be easier to attempt to do this server side as well (C# ex below)

  if (Request.UserAgent.ToUpper().Contains("PLAYSTATION"))
      //Send to correct page
      Response.Redirect("http://www.example.com/");
  }
Soatl
  • 10,224
  • 28
  • 95
  • 153
  • is PLAYSTATION the right user agent to be using? or should it be something like this Mozilla/5.0 (PLAYSTATION 3; 3.55) http://www.useragentstring.com/pages/Playstation%203/ – Matu Jul 21 '11 at 17:01
  • Playstation should work. Using `indexOf()` in javascript is like using a `String.contains()` call. It will return -1 if that string is not in the user agent, and all playstation user agents contain "Playstation". You can add an || if you want, but I don't think it would be necessary – Soatl Jul 21 '11 at 17:05