美文网首页
修改苹果的IOS系统下会出现手动设置标题失效

修改苹果的IOS系统下会出现手动设置标题失效

作者: ps_fba7 | 来源:发表于2017-06-08 20:51 被阅读0次

实现思路,在网页加载完成之后手动模拟一次网络请求,设置标题

实现思路,在网页加载完成之后手动模拟一次网络请求,设置标题

使用Jquery、zepto

/**
 * 修改页面标题
 * @param {[type]} title [description]
 */
utils.setTitle=function(title){
    var $body = $('body');
    document.title = title;

    var $iframe = $('<iframe style="display:none" src="https://m.putao.cn/PutaoLife/resources/images/favicon.png"></iframe>');
    $iframe.on('load',function() {
      setTimeout(function() {
          $iframe.off('load').remove();
      }, 0);
    }).appendTo($body);
};

使用原生JS

utils.setTitle=function(title){
    document.title = title;
    var mobile = navigator.userAgent.toLowerCase();
    if (/iphone|ipad|ipod/.test(mobile)) {
        var iframe = document.createElement('iframe');
        iframe.style.visibility = 'hidden';
        iframe.setAttribute('src', 'loading.png');
        var iframeCallback = function() {
            setTimeout(function() {
                iframe.removeEventListener('load', iframeCallback);
                document.body.removeChild(iframe);
            }, 0);
        };
    }
};

相关文章

网友评论

      本文标题:修改苹果的IOS系统下会出现手动设置标题失效

      本文链接:https://www.haomeiwen.com/subject/udwtqxtx.html