0

This has probably been answered before but i don't understand al the difficult research online so i ask it here And hope for a easy answer

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

This does not redirect me.

SidOfc
  • 4,552
  • 3
  • 27
  • 50

3 Answers3

2
var isiPad = navigator.userAgent.match(/iPad/i) != null;
//or by using
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua)

You can find other related information in the following links:

http://fellowtuts.com/jquery/ipadiphone-detection-using-javascript/

Detect iPad users using jQuery?

Community
  • 1
  • 1
Timothy Radier
  • 323
  • 4
  • 15
2

Instead of using location.replace use location.href

Your snippet becomes

if (navigator.userAgent.indexOf('iPad') > -1) {
    location.href = 'http://www.joey-games.byethost4.com/games/';
}

I've made two changes to your code

  • != to > in the if statement which is no biggie (nothing relevant)
  • changed method call from replace to href Taken from MDN

    The Location.replace() method replaces the current resource with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session History, meaning the user won't be able to use the back button to navigate to it.

    This basically says that if you use replace you cannot use the browsers back button to get to this page anymore, basically reducing the users user-experience since they'll get confused about what the back button does when they use your website.

This will redirect your users on the iPad to a different website however, you shouldn't do this - it's bad for your users and your website. (as partially explained above)

SidOfc
  • 4,552
  • 3
  • 27
  • 50
0

Iam Not gonna use The redirecting to go to "Joey-games.byethost4.com/games/" I wil redirect iPad users to: Joey-games.byethost4.com/mobile/iPad/ for a mobile site since flash player is not supported in safari yet