Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  134] [ 5]  / answers: 1 / hits: 34723  / 12 Years ago, sun, september 2, 2012, 12:00:00

I have a bunch of <a href=.html> links and want to make them all open in new windows.



I know I can do a search and replace all to add target=_blank to all my <a href=...> links.



However, is there a quick way, such as setting a CSS style, or adding some JavaScript code, to accomplish the same thing?


More From » html

 Answers
24

If you have a page consisting of only links, consider <base target=_blank>. This opens every link in a new window (but also includes the targets of forms, unless overridden with <form target=_self>.



As others have shown, without modifying the HTML source, you can use Javascript to iterate through all <a> tags and add the target attribute or add an event listener that sets the target attribute dynamically.


[#83285] Friday, August 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kennedi

Total Points: 702
Total Questions: 109
Total Answers: 111

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
;