Jquery 检测iPhone代码错误

Jquery 检测iPhone代码错误,jquery,Jquery,如果在iPhone5上查看我的页面,我会尝试重定向页面 以下是更新后的当前代码: <html> <head> <title>TEST</title> </head> <body> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.js"> $(document).r

如果在iPhone5上查看我的页面,我会尝试重定向页面

以下是更新后的当前代码:

<html>

<head>

<title>TEST</title>

</head>

<body>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.js">

$(document).ready(function () {
    var isiPhone = navigator.userAgent.toLowerCase().indexOf("iphone");
    var iHeight = window.screen.height;

if (isiPhone > -1 && iHeight <= 1336) {
    window.location("index2.html");
}
});
</script>

Start Page

</body>

</html>

试验
$(文档).ready(函数(){
var isiPhone=navigator.userAgent.toLowerCase().indexOf(“iphone”);
var iHeight=window.screen.height;

如果(isiPhone>-1&&iHeight您有额外的括号

if(isiPhone > -1) && (iHeight <= 1336) {

if(isiPhone>-1)和&(iHeight-1&&iHeight刚刚注意到一个巨大的错误。您的
标记包含代码或具有
src
属性,但它不能同时具有这两个属性

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.js">
    $(document).ready(function () {
        // your code
    });
    // your code cannot be inside a JavaScript file include
    // this needs to be totally empty!
</script>

$(文档).ready(函数(){
//你的代码
});
//您的代码不能位于JavaScript文件中
//这必须是完全空的!
相反,你必须这样做

请注意,JavaScript文件包含的
标记为空

<script type="text/javascript" src="yourfile.js"></script>

<script type="text/javascript">
    // your code in here
</script>

//你的代码在这里

谢谢您的快速回复,但仍然不起作用??好的,我已经按照建议更改了代码-但页面仍然无法重定向。console.log代码是什么?我如何在我的iPhone上减少它?谢谢。@RicSum,我不知道如何从iPhone上使用控制台。但是,为什么不能从中排除故障并测试逻辑您的桌面计算机?在桌面上运行逻辑并调整iPhone的参数。您还可以更改桌面Safari的用户代理(在开发者菜单下)请不要每次有人指出一个小的语法错误时都编辑你的代码。这不仅会使答案变得毫无意义,而且对那些试图提供帮助的人来说也是不公平的。请同时回顾一下这些材料:你还必须更加主动地描述你的问题n、 在只说“它失败了”的情况下转储代码是不可接受的。请确切解释它是如何失败的?您执行了哪些故障排除步骤?您验证了HTML吗?您是否收到任何控制台错误?就在
之后,您缺少开头的正文标记
。抱歉-只是刚刚加入,不确定这里的工作方式:)这是一个你可以玩的JSFIDLE。逻辑似乎起作用了:我刚刚得出了相同的结论-现在它起作用了!谢谢你的帮助-我想我快疯了。:)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.js">
    $(document).ready(function () {
        // your code
    });
    // your code cannot be inside a JavaScript file include
    // this needs to be totally empty!
</script>
<script type="text/javascript" src="yourfile.js"></script>

<script type="text/javascript">
    // your code in here
</script>