[WordPress] 外掛分享: jQuery.autoTarget for WordPress

首頁外掛目錄 › jQuery.autoTarget for WordPress
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
10+
安裝啟用
尚無評分
2897 天前
最後更新
問題解決
WordPress 3.0+ v1.0.0 上架:2014-12-16

內容簡介

當您寫符合標準的代碼,但仍希望將外部鏈結在新窗口中打開時有一點需要特別注意。XHTML 1.0 Strict 已棄用 “target” 屬性,HTML5 早期版本也有這種棄用情況,但現在又重新引用了。在任何情況下,確保對每個外部連結都設置目標屬性可能很繁瑣。

輸入 jQuery.autoTarget

這個 jQuery 外掛程式可以自動掃描頁面上的所有鏈接,如果 href 屬性的域名與該頁面所在域名不同,它會自動為您設置 target 屬性(target=”_blank”)。為了讓您更方便地設置樣式,它還會將所有外部鏈接設置為 “external-link” 的類。這真是易如反掌,而且僅佔 272 字節的空間!

不會覆蓋

為了保險起見,該腳本不會修改已經設置目標屬性的鏈接,所以如果您已經對目標屬性進行了某些操作,它不會將您現有的工作覆蓋掉。

在非 WordPress 网站使用 jQuery.autoTarget

如果您需要,我的 jQuery 插件 sans WordPress 插件可在 https://github.com/wknechtel/jQuery.autoTarget 下載。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「jQuery.autoTarget for WordPress」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

There is a little gotcha when you’re writing standards compliant code, but still want off-site links to open in new windows. XHTML 1.0 Strict deprecated the use of the “target” attribute. Early versions of HTML5 also had this deprecation, but have since brought it back. In either case, making sure the target attribute is set on every off-site link can be tedious.
Enter jQuery.autoTarget
Instead of going through the tedium of ensuring your target attributes are set, this jQuery plugin automatically scans all the links on a page, and sets the attribute for you (target=”_blank”) if the href attributes domain isn’t the same as the domain the page is served from. Just to sweeten the deal, it also sets any offsite link to have a class of “external-link”, so you can style offsite links in the manner of your choice. Easy-peasy. And it only weighs in at 272 bytes!
No-clobber
Just in case, the script does not touch any link that already has a target set, so if you’re already doing something with the target attribute, this won’t clobber your extant work.
Use of jQuery.autoTarget in Non-WordPress Sites
If you need it, my jQuery plugin sans wordpress plugin is available at https://github.com/wknechtel/jQuery.autoTarget

延伸相關外掛

文章
Filter
Apply Filters
Mastodon