-2

A quick question, How do I change to my 'iPad.html' page by detecting what browser or device that person is using.

Some one told me that this is the solution :

<script type="text/javascript"> // <![CDATA[
    if ((navigator.userAgent.indexOf('iPad') != -1)) {
        document.location = "http://www.mysite.com/ipad.html";
    } // ]]>
</script>

I just want to make sure that this is right.

GeekMasher
  • 1,066
  • 2
  • 11
  • 17

1 Answers1

0

That should work, but you should use the more standard window.location:

<script type="text/javascript">
    if ((navigator.userAgent.indexOf('iPad') != -1)) {
        window.location.href = "http://www.mysite.com/ipad.html";
    }
</script>

CDATA comments are not necessary, since nobody uses XML these days. (Or do you?)

Community
  • 1
  • 1
user123444555621
  • 148,182
  • 27
  • 114
  • 126