Easy Coding
  Forum Wiki Tagging Projekte Karte RSS
» Start
» All Recent Changes
» Wiki Suche
» Wiki Hilfe

Coder How To's

Algorithmen Informationen

edit SideBar

Neue Wiki Eintrage finden Sie unter easy-coding.de/wiki.

Externe Links mit JavaScript hervorheben

Um die Klasse dynamisch zu ändern verwenden wir die Universaleigenschaft className.

externe-links-hervorheben.html
  1. <title>Externe Links hervorheben</title>
  2. <style type="text/css">
  3. a.externalURL {
  4.         background-image: url('externalURL.png');
  5.         background-position: center right;
  6.         background-repeat: no-repeat;
  7.         margin-right: 3px;
  8.         padding-right: 15px;
  9.         background-color:#ffeecc;
  10. }
  11. a.externalURL:hover {
  12.         background-image: url('externalURLHover.png');
  13.         background-position: center right;
  14.         background-repeat: no-repeat;
  15. }
  16. </style>
  17.  
  18. <script type="text/javascript">
  19. function highlightExternalLinks(ressource) {
  20.         var domain = document.location.href.split("/");
  21.         var anchors = ressource.getElementsByTagName('a');
  22.         for (var i=0; i<anchors.length; i++) {
  23.                 var anchor = anchors[i];
  24.                 var destination = String(anchor.getAttribute("href"));
  25.                 if(destination.indexOf("://") > 0 && destination.split("/")[2] != domain[2])
  26.                         anchor.className = 'externalURL';
  27.  
  28.         }
  29. }
  30. </script>
  31. </head>
  32. <body onload="highlightExternalLinks(document)">
  33.  
  34.         <li><a href="intern.html">Interner relativer Link</a></li>
  35.         <li><a href="http://localhost/intern.html">Interner absoluter Link</a></li>
  36.         <li><a href="http://www.easy-coding.de">externer Link</a></li>
  37. </ul>
  38.  
  39. </body>
  40. </html>
Zuletzt geändert am 29.08.2007 16:25 Uhr
  Impressum