因爲本站有許多有趣的服務介紹,但是如果習慣像我一樣喜歡將連接都以右鍵選擇在新標籤頁開啓的話,可能會不太習慣在手機上瀏覽的方式,這樣照成思緒上中斷。
所幸,在新標籤頁開啓鏈接是可以透過植入 javascript
脚本來實現的。
🔖
有興趣可以到英文原址看該網站其他有趣的教學,順被你測試這外部鏈接是否以新標簽打開:Open External links on the new window on your ghost publication
步骤:
- Setting
>
Code Injection - Site Footer 中植入以下代碼:
<script>
const anchors = document.querySelectorAll('a');
for (x = 0, l = anchors.length; x < l; x++) {
const regex = new RegExp('/' + window.location.host + '/');
if (!regex.test(anchors[x].href)) {
anchors[x].setAttribute('target', '_blank');
anchors[x].setAttribute('rel', 'noopener');
}
}
</script>
- SAVE
最后:
应该任何网站都适用,或许可以在Typlog或是其他网站上尝试看看这个代码。
🔖
有興趣可以到英文原址看該網站其他有趣的教學,順被你測試這外部鏈接是否以新標簽打開:Open External links on the new window on your ghost publication