解决ios系统在safari浏览器中添加web应用程序到主屏幕,打开子链接会跳转到safari的问题

解决ios系统在safari浏览器中添加web应用程序到主屏幕,打开子链接会跳转到safari的问题

前言

ios系统的safari浏览器有一个功能可以将web应用程序添加到主程序,使得web程序像app一样全屏显示操作。

代码

<!-- 在 `head` 标签中添加描述 `html` 元数据的标签。表示允许该应用以全屏运行 -->
<meta name="apple-mobile-web-app-capable" content="yes">

<!-- 添加脚本 -->
<script>
  if (('standalone' in window.navigator) && window.navigator.standalone) {
    var noddy, remotes = false;
    document.addEventListener('click', function (event) {
      noddy = event.target;
      while (noddy.nodeName !== 'A' && noddy.nodeName !== 'HTML') noddy = noddy.parentNode;
      if ('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !==
          -1 || remotes)) {
        event.preventDefault();
        document.location.href = noddy.href;
      }
    }, false);
  }
</script>
  1. 添加 meta 标签后,web应用 会在主屏幕上以全屏显示,然当点击子链接时,依然会跳转到 safari 浏览器。

示例如下:
https://harmsworth.github.io/study-demo/2019/06/test3.html
在这里插入图片描述

  1. 添加 meta 标签并且添加上面的 js 脚本能全屏显示,当点击子链接时,会在 web应用 内跳转。

示例如下:
https://harmsworth.github.io/study-demo/2019/06/test5.html
在这里插入图片描述

参考

https://www.cnblogs.com/PeunZhang/p/3407453.html#meta
https://blog.csdn.net/lilinoscar/article/details/70270374
https://cloud.tencent.com/developer/article/1025378

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值