最近在做微信公众号开发,公司采用了前后端分离,前端用了vue,现在遇到一个需求是 当用户阅读一本书的时候,把书名做为网站title显示出来。

楼主采用

document.title = "文章标题"

安卓可以正常显示,但是ios在微信浏览器中不生效

最后的解决办法: 

setTimeout(function(){
          //利用iframe的onload事件刷新页面
          document.title = '标题';
          var iframe = document.createElement('iframe');
          iframe.style.visibility = 'hidden';
          iframe.style.width = '1px';
          iframe.style.height = '1px';
          iframe.onload = function () {
            setTimeout(function () {
              document.body.removeChild(iframe);
            }, 0);
          };
          document.body.appendChild(iframe);
        },0);


Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐