Merci Eric2a j’apprécie ton aide.
En faite la fonction doit être utilisée sans toucher au code HTML.
J’ai pu trouver la solution suivante :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LInk</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
$("a").click(function(){
$(this).attr("href", "http://www.mon-domaine.com/url/" + $(this).attr("href"));
});
});
</script>
</head>
<body>
<a href="http://www.google.com">google</a>
<br/>
<a href="http://www.yahoo.com">yahoo</a>
<br/>
<a href="/">Accueil</a> | <a href="/faq.html">FAQ</a> | <a href="test.html">Test</a>
</body>
</html> |
Cette solution marche très bien cependant y a-t-il une amélioration de cette fonction pour quelle ne soit pas exécuter sur les liens locaux (Accueil, FAQ, Test). Aussi définir les domaines à exclure (Yahoo par exemple)
<a href="http://www.google.com">google</a>
Résultat : http://www.mon-domaine.com/url/http://www.google.com
<a href="http://www.yahoo.com">yahoo</a>
Résultat : http://www.yahoo.com
Résultat : http://www.domaine-du-site.com
<a href="/faq.html">FAQ</a>
Résultat : http://www.domaine-du-site.com/faq.html
<a href="test.html">Test</a>
Résultat : http://www.domaine-du-site.com/test.html
Merci pour toute amélioration possible.
Partager