gpt4 book ai didi

javascript - 你如何制作书签更改页面图标?

转载 作者:行者123 更新时间:2023-11-30 10:59:53 24 4
gpt4 key购买 nike

在我开始之前,这不是重复的。为了解释我的目标,我想要一个书签,当点击它时,它会在不加载新选项卡的情况下更改页面图标。其他类似的问题给了你的书签一个图标,但没有达到我想要的效果。

这是我现在的代码:

data:text/html; charset=utf-8, <html><link rel="shortcut icon" href="http://link-to-my-icon.info/favicon.ico"></html>

它有效,但它改变了我的标签。我想保持选项卡打开,但编辑 HTML 以更改页面图标。我试过使用

javascript: document.write(<link rel="shortcut icon" href="http://transparent-favicon.info/favicon.ico">);

同样,但它什么也没做,而我的第一次尝试至少改变了图标。

非常感谢任何帮助,谢谢。

最佳答案

结帐 this gistdemo .

//source: https://gist.github.com/mathiasbynens/428626

document.head || (document.head = document.getElementsByTagName('head')[0]);

function changeFavicon(src) {
var link = document.createElement('link'),
oldLink = document.getElementById('dynamic-favicon');
link.id = 'dynamic-favicon';
link.rel = 'shortcut icon';
link.href = src;
if (oldLink) {
document.head.removeChild(oldLink);
}
document.head.appendChild(link);
}

关于javascript - 你如何制作书签更改页面图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58272946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com