Can anyone tell me of a way to open all links within an id in a new window?
+2
A:
Put this in the head:
$(function () {
$('#selector').attr('target', '_blank');
})
Nick Spiers
2009-12-01 11:22:02
Perfect! Thank you!
Jackson
2009-12-02 02:32:47
So accept the answer?
Gausie
2009-12-07 10:44:30
A:
Try this:
$('#myId').click(function(){
this.target = "_blank";
});
Regards, Paul Peelen
Paul Peelen
2009-12-01 11:24:46
A:
Is it a single function that will open all the hyperlinks within an ID in new windows? That's what I thought. :P
$("#some_id a").each(function (i) {
window.open(this.href);
});
o.k.w
2009-12-01 11:26:44
A:
If you say "all links" ,that i understand that any of specific link (e.g. may be more than one on the page) should guide to blank page.
For this case, you may do all needed links,that guide to blank page ,with specific id and dynamically generated postfix, e.g.:
link_1, link_2 etc.
so the script will look like:
var linkId = "[id*=" + "link_]";
$(linkId).attr('target', '_blank');
here is regexp used.
sergionni
2009-12-01 13:21:58
A:
I'd do it like this:
$('#myId a').click(function()
window.open(this.href);
return false;
});
jammus
2009-12-01 15:43:24