MediaWiki:Common.js

From UKTAPS.CO.UK Wiki
Revision as of 13:46, 15 June 2026 by Zhuo (talk | contribs)

Jump to: navigation, search

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() {
    // 读取模板中设置的 data-href
    var canonicalContent = $('.canonical-link').data('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('SEO: Canonical linked to ' + canonicalContent);
    }
});