J'ai créé une fonction très simple de vérifier si le lien est externe ou non.
En fait, si récupère le domaine en cours et les contrôles contre le lien sélectionnez, si l'URL est dans le même domaine, alors nous n'avons pas besoin d'une confirmation.
Toutefois, si l'URL n'est pas dans le domaine, nous envoyer un pop-up confirmant qu'ils veulent visiter ce site, si l'annuler leur séjour sur la page en cours.
Ci-dessous est la fonction:
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;
- }
- }
-
Voici quelques exemples sur la façon de mettre en œuvre les liens:
<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 vous avez besoin d'aide encore, me PM
