h5 app手机下载引导页 怎么兼容华为自带浏览器?

通过URL scheme打开APP,其他浏览器都支持,只是在华为自带浏览器不支持。

阅读 4.4k
1 个回答

你把这些代码放进去就能解决了

if (/Trident|msie|rv:/i.test(navigator.userAgent)) {
    navigator.language = navigator.userLanguage;
    document.addEventListener('DOMContentLoaded', function() {
        if (window.top == window) {
            var div = document.createElement('div');
            div.innerText = 'Internet Explorer may cause your funds to be stolen, it is recommended to use Google Chrome';
            div.className = 'shitIE-tips';
            document.body.appendChild(div);
            var s = document.createElement('link');
            s.rel = 'stylesheet';
            s.href = '/css/shitIE.css';
            document.body.appendChild(s);
        }
    }, false);

    window.addEventListener('hashchange', function() {
        location.reload();
    }, false);

}
if (typeof Element.prototype.closest != 'function') {
    var ep = Element.prototype;
    ep.matches = ep.matches || ep.matchesSelector || ep.webkitMatchesSelector || ep.msMatchesSelector || function(selector) {
        var node = this,
            nodes = (node.parentNode || node.document).querySelectorAll(selector),
            i = -1;
        while (nodes[++i] && nodes[i] != node);
        return !!nodes[i];
    };
    ep.closest = ep.closest || function(selector) {
        var el = this;
        while (el.matches && !el.matches(selector)) el = el.parentNode;
        return el.matches ? el : null;
    }
}
if (typeof Object.assign != 'function') {
    Object.assign = function(target) {
        if (target == null) {
            throw new TypeError('Cannot convert undefined or null to object');
        };
        target = Object(target);
        for (var index = 1; index < arguments.length; index++) {
            var source = arguments[index];
            if (source != null) {
                for (var key in source) {
                    if (Object.prototype.hasOwnProperty.call(source, key)) {
                        target[key] = source[key];
                    }
                }
            }
        };
        return target;
    };
}
if (typeof DOMParser != 'function') {
    (function(DOMParser) {
        "use strict";
        var proto = DOMParser.prototype,
            nativeParse = proto.parseFromString;

        // Firefox/Opera/IE throw errors on unsupported types
        try {
            // WebKit returns null on unsupported types
            if ((new DOMParser()).parseFromString("", "text/html")) {
                // text/html parsing is natively supported
                return;
            }
        } catch (ex) {}

        proto.parseFromString = function(markup, type) {
            if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
                var
                    doc = document.implementation.createHTMLDocument("");
                if (markup.toLowerCase().indexOf('<!doctype') > -1) {
                    doc.documentElement.innerHTML = markup;
                } else {
                    doc.body.innerHTML = markup;
                }
                return doc;
            } else {
                return nativeParse.apply(this, arguments);
            }
        };
    }(DOMParser));
}

if (typeof String.prototype.repeat != 'function') {
    String.prototype.repeat = function(num) {
        return new Array(num + 1).join(this);
    };
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
if (!Object.keys) {
    Object.keys = (function() {
        'use strict';
        var hasOwnProperty = Object.prototype.hasOwnProperty,
            hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
            dontEnums = [
                'toString',
                'toLocaleString',
                'valueOf',
                'hasOwnProperty',
                'isPrototypeOf',
                'propertyIsEnumerable',
                'constructor'
            ],
            dontEnumsLength = dontEnums.length;

        return function(obj) {
            if (typeof obj !== 'function' && (typeof obj !== 'object' || obj === null)) {
                throw new TypeError('Object.keys called on non-object');
            }

            var result = [],
                prop, i;

            for (prop in obj) {
                if (hasOwnProperty.call(obj, prop)) {
                    result.push(prop);
                }
            }

            if (hasDontEnumBug) {
                for (i = 0; i < dontEnumsLength; i++) {
                    if (hasOwnProperty.call(obj, dontEnums[i])) {
                        result.push(dontEnums[i]);
                    }
                }
            }
            return result;
        };
    }());
}
if (!Object.values) {
    var reduce = Function.bind.call(Function.call, Array.prototype.reduce);
    var isEnumerable = Function.bind.call(Function.call, Object.prototype.propertyIsEnumerable);
    var concat = Function.bind.call(Function.call, Array.prototype.concat);
    var keys = Reflect.ownKeys;

    Object.values = function values(O) {
        return reduce(keys(O), function(v, k) { concat(v, typeof k === 'string' && isEnumerable(O, k) ? [O[k]] : []), [] });
    };
    Object.entries = function entries(O) {
        return reduce(keys(O), function(e, k) {
            concat(e, typeof k === 'string' && isEnumerable(O, k) ? [
                [k, O[k]]
            ] : []), []
        });
    };
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题