我目前正在使用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功能的内容=“是”的“主屏幕”图标加载时,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崩溃日志,但据我所知,我无法理解那些没有源代码的人。
对于为什么会发生这种情况的任何见解都将非常感激,因为我不知所措。我一直在寻找几天试图找到有同样问题而没有运气的人。希望这是我看到的简单的事情。感谢。
答案 0 :(得分:1)
我遇到了同样的问题。到目前为止,我能够确定的是,正常访问网站时以及作为应用程序访问时,用户代理字符串是不同的。
当作为应用程序访问时,用户代理字符串缺少信息,导致页面呈现为ASP.NET无法识别且没有任何功能的浏览器,包括javascript。这会导致您看到的行为。
我找到了一个提供解决方案的链接,虽然我还没有能够让它为我工作。
http://blog.lavablast.com/post/2011/05/29/Gotcha-iPad-versus-ASPNET.aspx