17 ospiti e 0 utenti registrati online.
UserName
  Password  Registrati Ora! E' Gratuito!
 
Dreamweaver Javascript
Uno script per segnalare i link esterni
Contribuito da : Sergio
il Sabato 30 giugno 2007 alle 04:03:28
(Articolo letto 2709 volte)

Ecco uno script semplice e utile per segnalare ai visitatori di un sito se un link è esterno o interno al sito stesso.
Lo script infatti aggiunge automaticamente questo simbolo (tasto destro per scaricare questa immagine).
Altra funzionalità è quella che permette di aprire sempre in '_blank' i link esterni senza dover aggiungere il target nel codice.

Il primo passo è quello di creare un file javascript chiamato linkEnhancer.js


/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jeroen Haan | http://www.haan.net */
/* -----------------------------------------------
Link Enhancer - v.1.1
(c) 2007 www.haan.net
contact: jeroen@haan.net
You may use this script but please leave the credits on top intact.
Please inform us of any improvements made.
When useful we will add your credits.
------------------------------------------------ */

// Give the outbound links a blank target and their own style
// and optional the inbound too or vise versa
// It will leave the mailto alone and skip anchor tags without the href attribute


function enhanceLinks() {
var links = document.getElementsByTagName("a");
var thisDomain = document.domain.split('www.');
var thisDomain = (thisDomain[1]) ? thisDomain[1] : document.domain ;
for (var i = 0; i < links.length; i++) {
if(links[i].href.indexOf(thisDomain) == -1 && links[i].href != '') {
links[i].target = '_blank';
links[i].className = 'link_ext';
}
// or else do this too if you like
// else
// {
// links[i].target = '_self';
// links[i].className = 'link_int';
// }
}
}


// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}


addLoadEvent(function() {
enhanceLinks();
});


Poi di aggiungere al foglio di stile del proprio sito questa istruzione

.link_ext {
height: 20px;
background: url(link_ext.gif) no-repeat right 4px;
padding: 0 13px 0 0;
}


Tra i tag head infine aggiungiamo il riferimento allo script

<script type="text/javascript" src="linkEnhancer.js"></script>


Ti è piaciuto questo articolo?
Contatta il nostro partner

  • Altri articoli su Dreamweaver Javascript
  • Altri articoli di Harding
  • Chi è Harding


    L'articolo più letto relativo a Dreamweaver Javascript:
    Dreamveaver + Javascript = Carrello elettronico


    Ultime articoli riguardanti Dreamweaver Javascript:


    Visualizza la versione da stampa  Invia questo articolo ad un'amico

  • Commenti totali: 6 - Commenti visualizzati: 6
    Soglia Mostra
    I commenti sono sotto la responsabilità dello scrivente. Non ci riteniamo responsabili per il loro contenuto.
    joomla inviato da enny47 il Venerdì 20 luglio 2007 alle 03:11:45 (Punteggio: 1 - italian)
    Re: joomla inviato da Harding il Sabato 28 luglio 2007 alle 12:39:19 (Punteggio: 1 - italian)
    Ma il commento? inviato da Harding il Lunedì 23 luglio 2007 alle 12:01:19 (Punteggio: 1 - italian)
    Re: Ma il commento? inviato da Zubin il Martedì 24 luglio 2007 alle 11:48:21 (Punteggio: 1 - italian)
    Re: Re: Ma il commento? inviato da Sergionza il Venerdì 27 luglio 2007 alle 05:32:25 (Punteggio: 1 - italian)
    Re: Re: Re: Ma il commento? inviato da Zubin il Venerdì 27 luglio 2007 alle 05:59:36 (Punteggio: 1 - italian)

    Scrivi un commento

    Il tuo nome: Anonimo [Nuovo utente]
    Oggetto

    Commento
         


    Smilies:

    Lingua



    FAQ | Top 10 | Statistiche
    MMKit - Macromedia Community Shared Knowledge
    Tutti i loghi sono appartenenti ai rispettivi proprietari