[英]Change meta title based on url #id
我有一個 static html 網站。 我們的服務器不支持 php/c# 等...
JS / JQuery / Ajax 或其他人是否可以執行以下操作:
如果 url 是:
Https://example.com/page,元標題將是例如“主頁”。
Https://example.com/example#1,元標題將是“新元標題”
Https://example.com/example#29,元標題將是例如“不同的標題”
實際上,元標題是否可以動態顯示並根據 url #identifier 顯示不同的文本。
像這樣的事情應該這樣做:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.