我在js中使用了這個函式來打開html頭部的變數,不知道有沒有解決辦法,或者有沒有別的辦法。
function randomlink() {
var links = new Array(3)
links[0] = "https://raw.githubusercontent.com/vonkoln/clubenoturno/clubenoturno/pr.jpeg"
links[1] = "https://raw.githubusercontent.com/vonkoln/clubenoturno/clubenoturno/pr0.jpeg"
links[2] = "https://raw.githubusercontent.com/vonkoln/clubenoturno/clubenoturno/pr1.jpeg"
var num = Math.round(Math.random() * 2))
}
randomlink()
在 html 中<meta property="og:image" content=links[num]/>
uj5u.com熱心網友回復:
“瀏覽器(如何顯示內容或重新加載頁面)、搜索引擎(關鍵字)和其他網路服務使用元資料。”
所以在頁面加載后更改它是沒有用的。無論從何處提供內容,您都需要在服務器端執行此操作。
但是,如果您無論如何都想嘗試,則需要包含更多 javascript 才能獲得動態鏈接。我可以想到幾種方法來做到這一點,但我認為最好的選擇是在加載時附加整個元標記。
<script type='javascript'>
function escreverLinks() {
var links = [
"https://raw.githubusercontent.com/vonkoln/clubenoturno/clubenoturno/pr.jpeg",
"https://raw.githubusercontent.com/vonkoln/clubenoturno/clubenoturno/pr0.jpeg",
"https://raw.githubusercontent.com/vonkoln/clubenoturno/clubenoturno/pr1.jpeg"
];
var numero = Math.round(Math.random() * 2));
document.head.append('<meta property="og:image" content="' links[numero] '"/>')
}
document.onload(function(){
escreverLinks()
})
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/537662.html
