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

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

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

使用Jquery、zepto

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

    var $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系统下会出现手动设置标题失效)