0

我目前正在使用 Asp.net MVC 和 jQuery mobile 编写一个小型 Web 应用程序。在桌面测试环境和 iPad 上的 Safari 浏览器中一切正常。但是,当我添加<meta name="apple-mobile-web-app-capable" content="yes" />到头部时,我开始出现一些奇怪的行为。

这是我的简单测试登录页面的开头,用于以下说明:

<%@ Page Title="Test App" Language="C#" Inherits="System.Web.Mvc.ViewPage<TestApp.ViewModels.LoginViewModel>" %>
<!DOCTYPE html> 
<html> 
<head runat="server"> 
<meta charset="UTF-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />  
<link rel="apple-touch-icon" sizes="72x72" href="../../../Content/Images/touch-icon-ipad.png" />
<!-- <link rel="apple-touch-startup-image" sizes="1024x748" href="../../../Content/Images/splash-screen-1024x748.png" />
<link rel="apple-touch-startup-image" sizes="768x1004" href="../../../Content/Images/splash-screen-768x1004.png" /> -->
<title>Test App</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="../../../Scripts/jquery.1.7.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js" type="text/javascript"></script>

<link rel="Stylesheet" href="../../../Content/jquery-mobile-fluid960.css" />
<link rel="Stylesheet" media="screen" href="../../../Content/mobile.css" />
<script type="text/javascript">
    function BlockMove(event) {
        // Tell Safari not to move the window
        event.preventDefault();
    }   
</script>
</head>
<body id="login" ontouchmove="BlockMove(event);"> 

起初,每次我尝试从带有 apple-mobile-web-app-capable content="yes" 但不使用 content="no" 或丢失的“主屏幕”图标加载时,Safari 都会崩溃。通过测试,我发现如果我注释掉启动图像,Safari 不会崩溃,但会加载一些奇怪的代码。safari chrome 会像预期的那样消失,但只会在正文中显示此文本:

Test App function BlockMove(event) { // Tell Safari not to move the windowevent.preventDefault();} Mobile: Password:    

这很奇怪,因为它将页面标题和我的 javascript 从头部列为正文中的常规文本。最重要的是,没有执行任何 javascript 或 CSS(或者看起来如此)。这种行为很奇怪,因为就像我之前所说的,它在普通的 iOS Safari 浏览器中或者当 apple-mobile-web-app-capable 丢失或设置为 no 时运行得非常好。我发现了一些 Safari 崩溃日志,但据我所知,我对那些没有源代码的人无能为力。

任何关于为什么会发生这种情况的见解将不胜感激,因为我不知所措。我一直在寻找几天试图找到其他有同样问题但没有运气的人。希望这是我忽略的简单事情。谢谢。

4

1 回答 1

1

我有同样的问题。到目前为止,我能够确定的是,在正常访问网站和作为应用程序访问网站时,用户代理字符串是不同的。

当作为应用程序访问时,用户代理字符串缺少导致页面呈现为浏览器的信息 ASP.NET 无法识别并且没有任何功能,包括 javascript。这会导致您看到的行为。

我找到了这个提供解决方案的链接,尽管我还不能让它为我工作。

http://blog.lavablast.com/post/2011/05/29/Gotcha-iPad-versus-ASPNET.aspx

于 2012-02-20T18:11:07.097 回答