Come posso far aprire i link esterni in una nuova finestra con jQuery?

Come posso far aprire i link esterni in una nuova finestra con jQuery?

Aprire i link esterni in una nuova finestra è un'operazione molto semplice in jQuery.

Nella seguente soluzione dovete solo inserire l'URL di base del vostro sito.


$( "a" ).each(function() {
	var $a = $( this ),
		href = $a.attr( "href" );
		
	if( /^https?/.test( href ) && !/sito\.com/.test( href ) ) {
		$a.attr( "target", "_blank" );
	}
	
});

Torna su