User:Dinoguy1000/scripts/safeIEeditlinks.js

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button. Firefox: hold down the Shift key while clicking Reload (or press Ctrl-Shift-R). Google Chrome and Safari users can just click the Reload button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
if (navigator.appName == 'Microsoft Internet Explorer' && wgNamespaceNumber >= 0 &&
  (mw.config.get( "wgAction" ) == 'edit' || mw.config.get( "wgAction" ) == 'submit')) {
 
  function preventStrayClick(){
    var lnk = window.event.srcElement;
    if (lnk.nodeName != 'A'){ return; }
    if (! /^(javascript:|#)/i.test(lnk.getAttribute('href', 2))){
      lnk.setAttribute('target', '_new');
    }
  }
 
  $(function(){
    addHandler(document.getElementById('wikiPreview'), 'click', preventStrayClick);
    addHandler(document.getElementById('editform'), 'click', preventStrayClick);
    if (document.getElementById('catlinks')){ addHandler(document.getElementById('catlinks'), 'click', preventStrayClick); }
  });
 
}