Foros del Web » Programando para Internet » Javascript »

desactivar enlace temporalmente

Estas en el tema de desactivar enlace temporalmente en el foro de Javascript en Foros del Web. Aclaro que el código que viene a continuación funciona perfecto (al menos para el uso que estoy dándole yo;) así que en parte es una ...
  #1 (permalink)  
Antiguo 08/08/2011, 15:17
 
Fecha de Ingreso: noviembre-2004
Ubicación: Buenos Aires
Mensajes: 34
Antigüedad: 19 años, 5 meses
Puntos: 0
desactivar enlace temporalmente

Aclaro que el código que viene a continuación funciona perfecto (al menos para el uso que estoy dándole yo;) así que en parte es una aportación al foro y en parte tan solo quiero leer nuevas ideas y mejoras

La idea es la simple, data una tag del estilo
Código HTML:
<A href="destino.html" id='enlace1' onclick="Bloquear('enlace1',10)" target="frameX">enlace</A> 
usando el siguiente javascipt conseguimos que al hacer clic en el enlace se lo deshabilite por 10 segundos...

Código:
// Desactiva un Link durante N segundos después de un click
function Bloquear(objID, segundos) {
  var obj = document.getElementById(objID);
  if (obj != null) {
    if (obj.disabled) return false;
    desactivarLink(objID, "gray");
    setTimeout(function() {activarLink(objID);}, segundos*1000);
    return true;
  }
  return false;
}

// Desactiva un Link y lo pinta del color indicado
function desactivarLink(objID, color) {
  var obj = document.getElementById(objID);
  if (obj != null) {
    var href = obj.getAttribute("href");
    if(href && href != "" && href != null) {
      obj.setAttribute('hrefBack', href);
      var target = obj.getAttribute("target");
      if(target == '_blank') {
        window.open(href);
      }
      else if(target == '_top') {
        top.location.href = href;
      }
      else if(target == '_parent') {
        parent.location.href = href;
      }
      else if(target && target != "" && target != null && target != "_self") {
        parent.frames[target].location.href = href;
      }
	  else {
	    document.location.href = href;
	  }
    }
    obj.removeAttribute('href');
	obj.disabled = true;

    var onclick = obj.getAttribute("onclick");
    if(onclick != null) {
      obj.setAttribute('onclickBack', onclick);
      obj.setAttribute('onclick', "void(0);");
    }

	if (color != "" && color != null) {
      obj.setAttribute('colorBack', obj.style.color);
      obj.style.color = color;
	}
  }
}

// Reactiva un Link y le pone el color original
function activarLink(objID) {
  var obj = document.getElementById(objID);
  if (obj != null) {
    var hrefBack = obj.getAttribute("hrefBack");
    if(hrefBack != null) {
      obj.setAttribute('href', hrefBack);
      obj.removeAttribute('hrefBack');
    }
    obj.disabled = false;

    var onclickBack = obj.getAttribute("onclickBack");
    if(onclickBack != null) {
      obj.setAttribute('onclick', onclickBack);
      obj.removeAttribute('onclickBack');
    }

    var colorBack = obj.getAttribute("colorBack");
    if(colorBack != null) {
      obj.style.color = colorBack;
      obj.removeAttribute('colorBack');
    }
  }
}
Bueno, escucho ideas y espero que el script les sea útil...

Etiquetas: desactivar, disable, enable, enlace, html, link, onclick, settimeout, temporal
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:48.