/ Published in: JavaScript
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//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");