在iOS中浏览webApp时保持全屏模式

时间:2017-03-21 13:23:37

标签: javascript html ios fullscreen

我有一个网络应用程序,当使用元标记从iOS主屏幕通过图标启动时,以全屏模式打开

<meta name="apple-mobile-web-app-capable" content="yes">

我还希望在使用普通

浏览我的应用时保持全屏模式
<a href="category/pageA.html">Page A</a>

链接。我找到了几种解决方案手动设置location.href以防止iOS在Safari浏览器中打开新页面,但这似乎不起作用。

我目前的(非工作)方法如下:

var openLink = function (event) {
  event.preventDefault();
  let target = event.target;
  while (target.tagName.toUpperCase() !== 'A') {
    target = target.parentNode;
  }
  let href = target.href;
  window.location.href = href;
  return false;
};

然后在每个(内部)链接上使用

<a href="category/pageA.html" onclick="openLink()">Page A</a>

但这不起作用,点击后仍会打开Safari,以正常模式显示链接页面(无全屏和地址栏)。

我目前唯一没有尝试的是将我的Web应用程序重构为单页应用程序,因此其中没有“真实”链接。但如果可能的话,我想避免这种情况。

1 个答案:

答案 0 :(得分:0)

未经测试,但请尝试替换

window.location.href = href;

window.location.assign( href );

window.location.replace( href );

前者允许通过window.history.back()进行导航,后者不会。

相关问题