jQuery code snippet to load/open a link in new window. This code adds an event to the anchor tags that are given the “new-window” class and forces them to open in a new window.

$(function(){
 $('a.new-window').click(function(){
 window.open(this.href);
 return false;
 });
});

Advanced jQuery Load New Window Example

This code gets the id of a container div and then grabs the hidden url div element and then opens it in a new window.

function openblog(blog_id) {
	//alert(blog_id);
	$('#blog-wrap-'+blog_id).hide();
	var blogurl = $('#'+blog_id+'-url').text();
	var location = "http://domainname/index.php?blogurl="+blogurl;
	window.open(location);
}

The HTML Code

Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.


No Reader comments

Learn JavaScript for free!
Free course: Introduction to JavaScript

Yours when you take up a free 14-day SitePoint Premium trial.