Silababy
//需要jQuery、zepto版
function weixinTitle(){
    var $body = $(\'body\');
    document.title = \'title\';
    // hack在微信等webview中无法修改document.title的情况
    var $iframe = $(\'<iframe src="/favicon.ico"></iframe>\');
    $iframe.on(\'load\',function() {
        setTimeout(function() {
            $iframe.off(\'load\').remove();
        }, 0);
    }).appendTo($body);
}
//需要js原生版本
    function weixinTitle(title){
        var $body = document.body;
        document.title = title;
        // hack在微信等webview中无法修改document.title的情况
        var $iframe = createDom(\'<iframe src="/favicon.ico"></iframe>\');
        $iframe.addEventListener(\'load\', load);
        $body.appendChild($iframe);

        function load(){
            setTimeout(function() {
                $iframe.removeEventListener(\'load\', load);
                $body.removeChild($iframe);
            }, 0);
        }

        function createDom(htmlStr){
            var tmp = document.createElement(\'div\');
            tmp.innerHTML = htmlStr;
            var children = tmp.childNodes;
            for (var i = 0; i < children.length; i++) {
                if (children[i].nodeType ===1 ) {
                    return children[i];
                }
            }
            return;
        }
    }

分类:

技术点:

相关文章:

  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
猜你喜欢
  • 2021-12-18
  • 2021-12-18
  • 2021-12-18
  • 2021-12-18
  • 2022-12-23
  • 2021-12-18
  • 2021-12-14
相关资源
相似解决方案