app内部嵌套的h5,document.title设置title在ios中无效

app内部嵌套的h5,document.title设置title在ios中无效,第1张

处理如下:

const agent = navigator.userAgent;
const isiOS = !!agent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
const isAndroid = agent.indexOf('Android') > -1 || agent.indexOf('Adr') > -1; //android终端
// iOS
if (isiOS) {
  router.beforeEach((to, from, next) => {
    let title = "测试头部";
    if (to.meta.title) {
      title = to.meta.title;
    }
    let _body = document.getElementsByTagName('body')[0];
    document.title = title
    let _iframe = document.createElement('iframe')
    _iframe.style.display = 'none'
    _body .appendChild(_iframe)
    setTimeout(() => {
      document.body.removeChild(_iframe)
    }, 300)
    next();
  });
} else if (isAndroid) {
  router.beforeEach((to, from, next) => {
    let title = "测试头部";
    if (to.meta.title) {
      title = to.meta.title;
    }
    document.title = title;
    next();
  });
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/996677.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存