第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用 Javascript 刪除非自托管網(wǎng)站上的網(wǎng)站圖標(biāo)?

如何使用 Javascript 刪除非自托管網(wǎng)站上的網(wǎng)站圖標(biāo)?

阿晨1998 2023-12-11 16:06:59
<link rel="shortcut icon" href="https://files.writeas.org/favicon.ico" />是網(wǎng)站中的代碼嗎,我無法更改它,我只能更改 CSS 或注入我自己的 Javascript,那么我如何使用 Javascript 獲取這部分 HTML 代碼并注釋掉/覆蓋它從而刪除它?
查看完整描述

2 回答

?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

如果您無法刪除它,您可以使用以下代碼更改它(注意:刪除可能還不夠,因?yàn)樵S多瀏覽器默認(rèn)為 /favicon.ico)


//const ico_url = document.location.origin + '/favicon.ico'

const ico_url = 'https://api.adorable.io/avatar/256/your_icon.png'

let head = document.getElementsByTagName('head')[0]

console.dir(head)

var link;

let links = head.getElementsByTagName('link')

for(let i=0; i<links.length; i++) {

   if (links[i].rel == 'icon' || links[i].rel == 'shortcut icon') {

      link = links[i]

      console.log('old-icon: '+link.href)

      link.href = ico_url

      console.log('new-icon: '+link.href)

 

   }


}


if (typeof(link) == 'undefined') {

 console.log('creating favicon link !')

 link = document.createElement('link')

 link.setAttribute('rel','icon')

 link.setAttribute('type','image/png')

 link.setAttribute('href',ico_url) // new favicon ...

 document.getElementsByTagName('head')[0].appendChild(link)

}

console.log(link.href)


查看完整回答
反對(duì) 回復(fù) 2023-12-11
?
喵喵時(shí)光機(jī)

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊

也許你可以嘗試更換 head 標(biāo)簽...


let ico_url = 'https://api.adorable.io/avatar/256/head_icon.png'

 var head = document.createElement("head");

 link = document.createElement('link')

 link.setAttribute('rel','icon')

 link.setAttribute('type','image/png')

 link.setAttribute('href',ico_url) // new favicon ...

 head.appendChild(link)


 const html = document.getElementsByTagName('html')[0]

 html.appendChild(head)

 html.replaceChild(head,document.getElementsByTagName('head')[0])

console.dir(head)


查看完整回答
反對(duì) 回復(fù) 2023-12-11
  • 2 回答
  • 0 關(guān)注
  • 199 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)