你如何保持全屏模式的iPhone / iPad的networking应用程序?

我有一个离线工作的HTML5 iPad应用程序。 该应用程序基本上由4个html文件和3个aspx文件组成。 我的caching清单设置为只有html文件脱机可用,aspx文件需要networking连接。 这一切都很好!

现在,我已经到了要完成应用程序的最后一步,并尝试完成主屏幕图标,全屏模式下运行等。我已经添加了我认为是必要的元标记一旦将其添加到主屏幕,应用程序将首先以全屏模式启动。 我相信这些标签是正确的是,如果我在html页面之间来回导航,应用程序将(正确)启动并保持全屏模式。 我遇到的问题是让应用程序保持全屏模式,当点击一个服务器(aspx)链接。

当点击一个服务器链接(aspx)时,Mobile Safari会跳出浏览器模式并打开一个新窗口。 这种行为是不可接受的,我希望我在这里错过简单的东西。

以下是我在我的所有页面(html + aspx)上使用的元标记:

<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 

希望这提供了理解问题所需的所有必要信息。 我在这里看到了其他的链接,指出在主页上书签以外的任何页面都会导致一些人退出全屏模式。 这不是我遇到的问题,所以我想开始一个新的讨论。 同样,我觉得如果我在应用程序中有5个以上的HTML页面,它将继续保持全屏模式。 aspx页面是我的情况的问题。

让电脑做繁琐的工作,这就是他们的目标。

这是我用来避免重写所有链接的一段javascript代码。 因此,只有那些具有明确target = "_blank"属性的链接才会在Safari中打开。 所有其他链接将保留在networking应用程序内。

 var a=document.getElementsByTagName("a"); for(var i=0;i<a.length;i++) { if(!a[i].onclick && a[i].getAttribute("target") != "_blank") { a[i].onclick=function() { window.location=this.getAttribute("href"); return false; } } } 

下面是一个jQuery插件,可以帮助: https : //github.com/mrmoses/jQuery.stayInWebApp

它是一个类似的JavaScript解决scheme,但有一些更多的function。 默认情况下,它会附加到所有的链接,但是你可以使用它来附加到某个类或某些东西的链接。 它还检测iOS全屏模式,以避免妨碍其他浏览器和设备。

根据我的经验,任何外部链接似乎都会导致应用跳出全屏模式。 一个解决scheme是使用JavaScript和位置对象来pipe理您的导航。 如下:

HTML:

 <a href="javascript:navigator_Go('abc.aspx');">Go</a> 

使用Javascript:

 function navigator_Go(url) { window.location.assign(url); // This technique is almost exactly the same as a full <a> page refresh, but it prevents Mobile Safari from jumping out of full-screen mode } 

我知道以这种方式来修改链接是一件很痛苦的事情,但这是我find解决您所面临问题的唯一方法。

KPM解决scheme的问题在于,它会混淆应用程序所有页面中的所有链接,有时会导致难以发现的错误,尤其是在您的应用程序是ajax密集型的情况下。 我在github上find了一个更好的解决scheme。

为了方便起见,我正在复制下面的代码:

 (function(document,navigator,standalone) { // prevents links from apps from oppening in mobile safari // this javascript must be the first script in your <head> if ((standalone in navigator) && navigator[standalone]) { var curnode, location=document.location, stop=/^(a|html)$/i; document.addEventListener('click', function(e) { curnode=e.target; while (!(stop).test(curnode.nodeName)) { curnode=curnode.parentNode; } // Condidions to do this only on links to your own app // if you want all links, use if('href' in curnode) instead. if('href' in curnode && ( curnode.href.indexOf('http') || ~curnode.href.indexOf(location.host) ) ) { e.preventDefault(); location.href = curnode.href; } },false); } })(document,window.navigator,'standalone'); 

我解决的解决scheme是Waypoint处理内部链接。 它有一个开放的()方法的外部链接的工作,直到iOS 6之后,你需要这个 iOS 7的其他修复 。

 // Internal link handling Waypoints .intercept('a') .ignore('a[rel=external], a[rel=blank], a[target=_blank], a[href$=".pdf"]'); // .resume(); // External link handling... $('a').on('click', function(e) { var href = $(this).attr('href'); if ($(this).is('a[rel=external], a[rel=blank], a[target=_blank], a[href$=".pdf"]') || (href.indexOf('http') >= 0 && href.indexOf(document.location.host) === -1)) { e.preventDefault(); var link = this; if (navigator.standalone) { if (/iP(hone|od|ad) OS 7/.test(navigator.userAgent)) { // iOS 7 external link polyfill e.stopPropagation(); // Your custom dialog code for iOS 7 and external links } else { Waypoints.open(href); } } else { window.open(href); } } }); 

还有Swipy.js你应该检查出来,它包括航点作为一个库,我可能包括所有这些链接处理和iOS 7修补程序,如果它是值得的。

将此添加到索引文件将会有所斩获。

  <head> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-touch-fullscreen" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <script type”javascript="" text”=""> document.addEventListener('DOMContentLoaded', function(){ var updateStatusBar = navigator.userAgent.match(/iphone|ipad|ipod/i) && navigator.appVersion.match(/OS (\d)/) && parseInt(navigator.appVersion.match(/OS (\d)/)[1], 10) >= 7 && window.navigator.standalone; if (updateStatusBar) { document.body.classList.add('platform-ios'); document.body.classList.add('platform-cordova'); } }); </script>