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?
Open in a new window To open a link in a new browser window, hold the Shift on then click the link or right-click the link and select Open link in New Window.
Just right click on the link and hold it to drag a box around the links. When you release the right click of your mouse, all those links will open in new tabs. Open links in new tabs are the default action of the add-on, but you can change it open in new windows.
Press Ctrl and click a link. Opens the link in a new tab and switches to the newly opened tab. Press Ctrl+Shift and click a link. Opens the link in a new window.
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.
If you have jQuery it's simple
$("a").attr("target", "_blank");
Or regular Javascript
var links = document.links; for (var i = 0; i < links.length; i++) { links[i].target = "_blank"; }
As per @Lekensteyn's suggestion, without Javascript (added for Completeness)
<base target="_blank">.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With