target="_blank" Replacement using JavaScript

The following script will open all links containing rel="_blank" attribute in a new window, all other links will open as usual.

Try it:


<script type="text/javascript">
	/*  The code below cannot be used together, use solution 1 or solution 2  */
	//  Solution 1
	$(document).ready(function(){
		$('A[rel="_blank"]').each(function(){
		    $(this).attr('target', '_blank');
		});
	});
	
	//  Solution 2
	$(document).ready(function(){
	    $('A[rel="_blank"]').click(function(){
	        window.open($(this).attr('href'));
	        return false;
	    });
	});
</script>
    

View Full Tutorial: W3C Valid target="_blank"

The ajaxBlender team specializes in web development to build advanced, interactive JavaScript/AJAX web applications driven by jQuery, MooTools, Ext.JS, and script.aculo.us on various server-side platforms including PHP and ASP.NET.