美文网首页Ionic Framework
Ionic 2 favicon设置无效临时解决方案

Ionic 2 favicon设置无效临时解决方案

作者: 剪影Boy | 来源:发表于2017-02-25 14:42 被阅读250次

在Ionic项目中,favicon.ico默认在your-ionic-project/src/assets/icon路径下,开始页面indexht.html中也有对应的设置: <link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">。然而,ionic serve所渲染网页的图标看起来和favicon.ico并没有什么关系,哪里出错了呢?

经过反复测试发现,indexht.html里的

<link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">

在执行ionic serve后,总是会被自动替换成

<link rel="icon" type="image/png" href="data:image/png;base64,...">

替换后图标是Ionic的默认图标,不会变化。

在Ionic论坛也提到了这个问题——How to set Ionic2 rc0 favicon now?,猜测或为Ionic CLI本身的bug.

目前还没找到有效的解决方案,自己想了一个临时的:

<!-- index.html -->
<script>
    setTimeout(function() {
        var links = document.getElementsByTagName('link');
        var linksLength = links.length;
        for (var i = 0; i < linksLength; i++) {
            if ('icon' === links[i].rel) {
                links[i].type = 'image/x-icon';
                links[i].href = 'assets/icon/favicon.ico';
            }
        }
        links = null;
    }, 0);
</script>

思路挺简单,就是在Ionic CLI自动替换后,再替换回来...

个人技术博客 biebu.xin,原文链接——Ionic 2 favicon设置无效临时解决方案

相关文章

网友评论

    本文标题:Ionic 2 favicon设置无效临时解决方案

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