Reputation: 1205
I am trying to figure out how to write a "switch statement" so if one particular (let's call it 'yourdomain.com') external URL matches it does not open in a new window, the rest will. Can someone lend a hand in teaching me?
jQuery(function ($) {
$('a[href^="http://"]')
.not('[href*="http://mydomain.com"]')
.attr('target', '_blank');
e.g.
mydomain.com = this will not open a new window because it's my URL
yourdomain.com = this particular URL will not open in a new window even though it's an external URL
anyotherdomain.com = every other external URL besides the one above will open in a new window
Upvotes: 0
Views: 164
Reputation: 1205
Solved it by adding another .not()
jQuery(function ($) {
$('a[href^="http://"]')
.not('[href*="http://mydomain.com"]').not('[href*="http://yourdomain.com"]')
.attr('target', '_blank');
Upvotes: 1
Reputation: 2884
$(function() {
var elms = $('a[href^="http://"]');
$.each(elms, function() {
var current_link = $(this).attr("href");
if (current_link == "yoururl") {
$(this).attr('target', '_blank');
}
});
});
could this be helpful?
Upvotes: 1