Return to Snippet

Revision: 8619
at July 15, 2009 04:33 by 1man


Updated Code
//Grab the href, open it in a window and cancel the click action
$("a[href^='http']").click(function(){window.open(this.href); return false;});
//Add target = blant to the external link
$("a[href^='http']").attr('target','_blank');
//Similar to the first, only using your domain name
$("a:not([href*='yourdomainnamehere.com'])").click(function(){
		window.open(this.href);
		return false;
	}).attr("title", "Opens in a new window");

Revision: 8618
at January 21, 2009 12:47 by 1man


Updated Code
//Grab the href, open it in a window and cancel the click action
$("a[@href^='http']").click(function(){window.open(this.href); return false;});
//Add target = blant to the external link
$("a[@href^='http']").attr('target','_blank');
//Similar to the first, only using your domain name
$("a:not([@href*='yourdomainnamehere.com'])").click(function(){
		window.open(this.href);
		return false;
	}).attr("title", "Opens in a new window");

Revision: 8617
at October 1, 2008 06:04 by 1man


Initial Code
//Grab the href, open it in a window and cancel the click action
$("a[@href^='http']").click(function(){window.open(this.href); return false;});
//Add target = blant to the external link
$("a[@href^='http']").attr('target','_blank');

Initial URL

                                

Initial Description
Two different ways to open an external link (ones that start in http) in a new window. I know this isn't a great thing to do, but some clients _need_ to have it.

Initial Title
jQuery open external link in new window

Initial Tags
link, window, jquery

Initial Language
JavaScript