Abra la ventana, pero con alerta y luego redireccionar

  • Mozzi
  • Student
  • Student
  • No Avatar
  • Registrado: Ago 19, 2004
  • Mensajes: 70
  • Status: Offline

Nota Junio 21st, 2010, 4:16 am

Tengo alrededor de 30 enlaces en mi página web.

Necesito un javascript para abrir una página .. entonces alertar a la persona que su contenido externo .. a continuación, haga clic en Aceptar cuando se abre la url.

He probado muchos guiones, pero todos parecen funcionar bien, pero tengo que hacer todas las funciones durante 30 urls ..??!!!?

Es su manera fácil / script...que puedo aplicar a mi enlace url .. por lo que sólo se abre la URL mencionado .. alerta .. y luego redireccionar a la página solicitada...
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Junio 21st, 2010, 4:16 am

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de Usuario
  • Registrado: May 22, 2004
  • Mensajes: 3415
  • Loc: Richland, WA
  • Status: Offline

Nota Junio 21st, 2010, 7:28 am

Youd ¿Estaría dispuesto a utilizar un framework javascript como Jquery?

Esto no es una solución completa, pero es un buen punto de partida.

JAVASCRIPT Código: [ Select ]
// Creating custom :external selector
$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
};
 
// Add 'external' CSS class to all external links
$('a:external').addClass('external');
  1. // Creating custom :external selector
  2. $.expr[':'].external = function(obj){
  3.     return !obj.href.match(/^mailto\:/)
  4.             && (obj.hostname != location.hostname);
  5. };
  6.  
  7. // Add 'external' CSS class to all external links
  8. $('a:external').addClass('external');

http://jquery-howto.blogspot.com/2009/0 ... -with.html
#define NULL (::rand() % 2)
  • PaulR
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Jul 10, 2010
  • Mensajes: 5
  • Status: Offline

Nota Julio 24th, 2010, 9:37 pm

He creado una función muy sencilla para comprobar si el enlace es externo o no.

Básicamente, si obtiene el dominio actual y los controles contra el enlace de elegir si la dirección se encuentra dentro del mismo dominio, entonces no necesitamos una confirmación.
Sin embargo, si la dirección no está dentro del dominio, enviamos un pop-up que confirma que deseen visitar este sitio, si la cancelación se quedan en la página actual.

A continuación se muestra la función:

JAVASCRIPT Código: [ Select ]
function exLinks(URL){
  // Check the domain against the link.
  // If the link is not within the current Domain, prompt the user.
  if(!URL.indexOf(document.domain)!=-1) {
    msg = "This is an external link, are you sure you wish to visit this site?"; // Pop-up message, for confirmation.
 
    // If confirmed, redirect to the external website
    if(confirm(msg)) {
      window.location=URL;
    }
 
  } else {
    // If the URL is within the same domain, no confirmation needed.
    window.location=URL;
  }
}
 
  1. function exLinks(URL){
  2.   // Check the domain against the link.
  3.   // If the link is not within the current Domain, prompt the user.
  4.   if(!URL.indexOf(document.domain)!=-1) {
  5.     msg = "This is an external link, are you sure you wish to visit this site?"; // Pop-up message, for confirmation.
  6.  
  7.     // If confirmed, redirect to the external website
  8.     if(confirm(msg)) {
  9.       window.location=URL;
  10.     }
  11.  
  12.   } else {
  13.     // If the URL is within the same domain, no confirmation needed.
  14.     window.location=URL;
  15.   }
  16. }
  17.  


He aquí algunos ejemplos sobre cómo aplicar los enlaces:
HTML Código: [ Select ]
<a onClick="exLinks('http://www.Ozzu.com');" href="javascript&#058;void();">www.ozzu.com</a><br>
<a onClick="exLinks('URL Here');" href="javascript&#058;void();">Link Here</a><br>
<a onClick="exLinks('URL Here');" href="javascript&#058;void();">Link Here</a>
 
  1. <a onClick="exLinks('http://www.Ozzu.com');" href="javascript&#058;void();">www.ozzu.com</a><br>
  2. <a onClick="exLinks('URL Here');" href="javascript&#058;void();">Link Here</a><br>
  3. <a onClick="exLinks('URL Here');" href="javascript&#058;void();">Link Here</a>
  4.  


Si necesita ayuda todavía, me PM 8)

Publicar Información

  • Total de mensajes en este tema: 3 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 131 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC