2012-02-19 63 views
-2

一个简短的问题,我如何通过检测该人正在使用的浏览器或设备来更改为我的'iPad.html'页面。当iPad使用它时,网站的模板发生变化

有些人告诉我,这是解决方案:

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

我只是想确保,这是正确的。

+0

这是对吗? – GeekMasher 2012-02-19 09:03:12

+1

你应该测试它.. – home 2012-02-19 09:05:40

+0

不管你信不信,有些人在那里没有iPad。 – user123444555621 2012-02-19 09:18:16

回答

0

这应该工作,但你应该使用更多的标准window.location

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

CDATA意见are not necessary,因为没有人使用XML这些天。 (或者你呢?)

+0

好的,谢谢,我会试试看。 – GeekMasher 2012-02-19 09:25:27

相关问题