Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make all <a> has the same target="_self"

How can I make all <a> link has the same target of "_self" through jQuery or javascript?

like image 748
Henry Avatar asked Aug 10 '11 22:08

Henry


3 Answers

Put this in the <head>:

<base target="_self">

No need for JavaScript - HTML has the feature built in!

like image 58
RichieHindle Avatar answered Oct 03 '22 08:10

RichieHindle


$('a[href]').attr('target','_self');

Note: This will override all ANCHOR tag's target attribute on the page. RichieHindle's answer would be best if you just want to add them where they aren't declared.

like image 28
Jared Farrish Avatar answered Oct 03 '22 09:10

Jared Farrish


$('a').attr('target', '_self');
like image 35
Jacek Kaniuk Avatar answered Oct 03 '22 07:10

Jacek Kaniuk