MediaWiki:Gadget-exlinks.js

Revision as of 18:00, 31 March 2020 by Joelmartin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 / Edge: 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.
// **********************************************************************
// **                 ***WARNING GLOBAL GADGET FILE***                 **
// **             changes to this file affect many users.              **
// **           please discuss on the talk page before editing         **
// **                                                                  **
// **********************************************************************
/**
 * @source mediawiki.org/wiki/Snippets/Open_external_links_in_new_window
 * @version 4
 */
mw.hook('wikipage.content').add(function($content) {
        $content.find('a.external').each(function () {
                // Can't use wgServer because it can be protocol relative
                // Use this.href property instead of this.getAttribute('href')  because the propery
                // is converted to a full URL (including protocol)
                if (this.href.indexOf(location.protocol + '//' + location.hostname) !== 0) {
                        this.target = '_blank';
                }
        });
});