MediaWiki:Common.js
From UKTAPS.CO.UK Wiki
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function() {
// 这个脚本会自动寻找页面内容中存在的 canonical 链接(即你用模板生成的那个)
// 并将其移动到网页头部,确保 Google 抓取器能精准识别
var canonicalContent = $('.canonical-link').attr('href');
if (canonicalContent) {
// 移除现有的(如果存在)
$('link[rel="canonical"]').remove();
// 创建新的并放入 head
var link = document.createElement('link');
link.setAttribute('rel', 'canonical');
link.setAttribute('href', canonicalContent);
document.head.appendChild(link);
console.log('Canonical tag injected/moved to head: ' + canonicalContent);
}
});