連結
Last update: Wed Feb 26 2025 00:00:00 GMT+0000 (Coordinated Universal Time)
附註:
超連結是連線網站與內容的必要元素。 若要建立連結,只要在Word或Google檔案中使用插入連結選項即可。
您可以在所有預設內容和不同的格式選項中新增連結。
在Word和Google Docs中,僅接受絕對連結,這通常比較容易從瀏覽器複製貼上。 系統會自動將連結轉換為與網站相對,而外部連結則會保持絕對狀態。
連結的使用範圍通常超出文字連結和參考,例如內嵌在頁面中的內嵌媒體或參考片段。
範例:
內容結構:
檢視檔案中的內容
程式碼:
由於連結被視為預設內容,因此會在專案或區塊CSS程式碼中設定其樣式。 通常不會使用JavaScript程式碼。
樣板專案中沒有連結相關的樣式程式碼。
特別注意事項: Microsoft Word Online不允許在影像上使用連結,所以解決方法是讓作者直接在影像下方放置連結,然後在使用者端換行,例如:
/**
* Wraps images followed by links within a matching <a> tag.
* @param {Element} container The container element
*/
function wrapImgsInLinks(container) {
const pictures = container.querySelectorAll('picture');
pictures.forEach((pic) => {
const link = pic.nextElementSibling;
if (link && link.tagName === 'A' && link.href) {
link.innerHTML = pic.outerHTML;
pic.replaceWith(link);
}
});
}
特別注意事項: 建議根據使用者端的外部連結或PDF (例如)處理需要在新視窗中開啟的特定連結,例如:
/**
* Handles external links and PDFs to be opened in a new tab/window
* @param {Element} main The main element
*/
export function decorateExternalLinks(main) {
main.querySelectorAll('a').forEach((a) => {
const href = a.getAttribute('href');
if (href) {
const extension = href.split('.').pop().trim();
if (!href.startsWith('/')
&& !href.startsWith('#')) {
if (!href.includes('xyz.com') || (extension === 'pdf')) {
a.setAttribute('target', '_blank');
}
}
}
});
}
recommendation-more-help
10a6ce9d-c5c5-48d9-8ce1-9797d2f0f3ec