簡體   English   中英

如何從 url 獲取描述?

[英]How to get description from a url?

您好,我正在創建一個 chrome 擴展,需要從 url 獲取描述(如果有)。 嘗試尋找示例,但它們似乎只適用於輸入的硬數據 url。 我從我的content.js得到我的 url -->

chrome.runtime.sendMessage({
  url: window.location.href
})

我現在想看看如何從 url 中獲取描述/元標記。 任何提示或解決方案都會有所幫助。

雖然document.head

如果發現良好,您可能想先嘗試描述,否則尋找og:twitter:標簽。

// title
document.head.querySelector('title').innerText

// normal description meta tag
document.head.querySelector('meta[name="description"]').getAttribute('content')

// twitter:
document.head.querySelector('meta[name="twitter:description"]').getAttribute('content')

// og:
document.head.querySelector('meta[name="og:description"]').getAttribute('content')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM