我有一個靜態 html 網站。我們的服務器不支持 php/c# 等...
JS / JQuery / Ajax 或其他人可以執行以下操作:
如果網址是:
https://example.com/page ,元標題將是例如“主頁”。
https://example.com/example#1 ,元標題將是“新元標題”
https://example.com/example#29 ,元標題將是例如“不同的標題”
實際上,元標題是否可以動態顯示并根據 url #identifier 顯示不同的文本。
uj5u.com熱心網友回復:
像這樣的事情應該這樣做:
<script>
function setTitleBasedOnUrlHash() {
var hash = window.location.hash;
if (hash === '#1') {
document.title = 'new meta title';
} else if (hash === '#2') {
document.title = 'a different title';
}
// ...more else ifs here...
}
window.onload = setTitleBasedOnUrlHash;
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/537486.html
上一篇:修改輸入欄位時錯誤所有產品都更新
