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:
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;
}
}
- 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;
- }
- }
-
He aquí algunos ejemplos sobre cómo aplicar los enlaces:
<a onClick="exLinks('http://www.Ozzu.com');" href="javascript:void();">www.ozzu.com</a><br>
<a onClick="exLinks('URL Here');" href="javascript:void();">Link Here</a><br>
<a onClick="exLinks('URL Here');" href="javascript:void();">Link Here</a>
- <a onClick="exLinks('http://www.Ozzu.com');" href="javascript:void();">www.ozzu.com</a><br>
- <a onClick="exLinks('URL Here');" href="javascript:void();">Link Here</a><br>
- <a onClick="exLinks('URL Here');" href="javascript:void();">Link Here</a>
-
Si necesita ayuda todavía, me PM
