MediaWiki:Common.js: различия между версиями

Материал из iSphinx Home Wiki

Нет описания правки
Нет описания правки
 
Строка 1: Строка 1:
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
function targetBlank() {
$('a').each(function() {
  // remove subdomain of current site's url and setup regex
   var a = new RegExp('/' + window.location.host + '/');
  var internal = location.host.replace("www.", "");
  if(!a.test(this.href)) {
      internal = new RegExp(internal, "i");
       $(this).click(function(event) {
     
          event.preventDefault();
   var a = document.getElementsByTagName('a'); // then, grab every link on the page
          event.stopPropagation();
  for (var i = 0; i < a.length; i++) {
          window.open(this.href, '_self');
    var href = a[i].host; // set the host of each link
      });
    if( !internal.test(href) ) { // make sure the href doesn't contain current site's host
       a[i].setAttribute('target', '_blank'); // if it doesn't, set attributes
    }
   }
   }
});
}

Текущая версия от 04:07, 11 мая 2024

function targetBlank() {
  // remove subdomain of current site's url and setup regex
  var internal = location.host.replace("www.", "");
      internal = new RegExp(internal, "i");
      
  var a = document.getElementsByTagName('a'); // then, grab every link on the page
  for (var i = 0; i < a.length; i++) {
    var href = a[i].host; // set the host of each link
    if( !internal.test(href) ) { // make sure the href doesn't contain current site's host
      a[i].setAttribute('target', '_blank'); // if it doesn't, set attributes
    }
  }
}