Javascript 如何将重定向设置为iPad用户?

Javascript 如何将重定向设置为iPad用户?,javascript,Javascript,这个问题以前可能已经得到了回答,但我不理解所有在线的困难研究,所以我在这里问它,希望得到一个简单的答案 <script type="text/javascript"> // <![CDATA[ if ((navigator.userAgent.indexOf('iPad') != -1)) { location.replace = "http://www.joey-games.byethost4.com/games/"; } // ]]> //

这个问题以前可能已经得到了回答,但我不理解所有在线的困难研究,所以我在这里问它,希望得到一个简单的答案

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

这不会改变我的方向

var isiPad = navigator.userAgent.match(/iPad/i) != null;
//or by using
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua)
您可以在以下链接中找到其他相关信息:

您可以在以下链接中找到其他相关信息:


而不是使用
位置。替换
使用
位置。href

您的代码片段变为

if (navigator.userAgent.indexOf('iPad') > -1) {
    location.href = 'http://www.joey-games.byethost4.com/games/';
}
我对你的代码做了两处修改

  • =
    中的
    if
    语句,该语句没有什么大的意义(没有任何相关)
  • 将方法调用从
    replace
    更改为
    href
    取自

    Location.replace()方法将当前资源替换为所提供URL上的资源。与assign()方法的区别在于,在使用replace()之后,当前页面将不会保存在会话历史记录中,这意味着用户将无法使用back按钮导航到它

    这基本上是说,如果您使用
    replace
    ,您就不能再使用浏览器后退按钮来访问此页面,这基本上减少了用户的用户体验,因为用户在使用您的网站时会对后退按钮的功能感到困惑


这会将iPad上的用户重定向到另一个网站,但是,你不应该这样做-这对你的用户和网站都不好。(如上部分解释)

而不是使用
位置。替换
使用
位置。href

您的代码片段变为

if (navigator.userAgent.indexOf('iPad') > -1) {
    location.href = 'http://www.joey-games.byethost4.com/games/';
}
我对你的代码做了两处修改

  • =
    中的
    if
    语句,该语句没有什么大的意义(没有任何相关)
  • 将方法调用从
    replace
    更改为
    href
    取自

    Location.replace()方法将当前资源替换为所提供URL上的资源。与assign()方法的区别在于,在使用replace()之后,当前页面将不会保存在会话历史记录中,这意味着用户将无法使用back按钮导航到它

    这基本上是说,如果您使用
    replace
    ,您就不能再使用浏览器后退按钮来访问此页面,这基本上减少了用户的用户体验,因为用户在使用您的网站时会对后退按钮的功能感到困惑


这会将iPad上的用户重定向到另一个网站,但是,你不应该这样做-这对你的用户和网站都不好。(如上部分解释)

我不会使用重定向转到“Joey games.byethost4.com/games/”我会将iPad用户重定向到移动站点:Joey-games.byethost4.com/mobile/iPad/,因为safari不支持flash player

我不会使用重定向转到“Joey games.byethost4.com/games/”我会将iPad用户重定向到:Joey-games.byethost4.com/mobile/iPad/,因为safari还不支持flash player