zoukankan      html  css  js  c++  java
  • 微信中修改title

    //需要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;
            }
        }
    
  • 相关阅读:
    Linux中的用户和用户组
    GCC编译过程
    C++设计模式——单例模式(转)
    快速排序之python
    归并排序之python
    计数排序之python
    希尔排序之python
    插入排序之python
    选择排序之python
    冒泡排序之python
  • 原文地址:https://www.cnblogs.com/Silababy/p/5970642.html
Copyright © 2011-2022 走看看