Javascript 网页中的移动检测未捕获语法错误:控制台中的意外令牌| |

Javascript 网页中的移动检测未捕获语法错误:控制台中的意外令牌| |,javascript,html,mobile,Javascript,Html,Mobile,我有一个脚本来检测用户是否正在使用手机: <script type="text/javascript"> //<![CDATA[ var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())); if (mobile) || (navigator.userAgent.match(/iPhone/i)) ||

我有一个脚本来检测用户是否正在使用手机:

<script type="text/javascript">
//<![CDATA[ 
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) ||  (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) {
    window.location.href = 'http://www.site.com/mobile/';
}
//]]>
</script>

您正在测试的布尔表达式必须用paren包装

if ((mobile) ||  (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))

您正在测试的布尔表达式必须用paren包装

if ((mobile) ||  (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))

所有表达式都需要用括号括起来

<script type="text/javascript">
//<![CDATA[ 
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if ((mobile) ||  (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
    window.location.href = 'http://www.site.com/mobile/';
}
//]]>
</script>

//

所有表达式都需要用括号括起来

<script type="text/javascript">
//<![CDATA[ 
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if ((mobile) ||  (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
    window.location.href = 'http://www.site.com/mobile/';
}
//]]>
</script>

//

您必须始终这样做。您必须始终这样做。